1

Well, I have an EAR project with the following structure:

EarSample
  - EarSample-ejb.jar
  - EarSample-web.war

Inside the EJB module a have a simple stateless session bean with no interfaces (no-view interface).

What's happening is that I'm not being able to inject that EJB in a JSF managed bean packaged in war module. Netbeans not even sees the class.

I've already tried GF 3/4 and Payara.

Any help will be appreciated. Thank you.

Jaumzera
  • 2,305
  • 1
  • 30
  • 44
  • 1
    Is the ejb.jar in the build class path of your web.war? If your project is maven based, is the ejb.jar a dependency of web.war project? – OndroMih Mar 16 '17 at 08:17
  • You're right, it's a maven project. I've added EJB module as "provided" dependence and it worked perfectly. Thank you. – Jaumzera Mar 16 '17 at 12:13

2 Answers2

1

Well, as suggested by @OndrejM, I only added EJB-module dependence in WAR's pom.xml as "provided" and it worked perfectly.

    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>EarSample-ejb</artifactId>
        <version>${project.version}</version>
        <scope>provided</scope>
    </dependency>
Jaumzera
  • 2,305
  • 1
  • 30
  • 44
  • You can mark this answer as the correct answer, even if it is yours ;) – OndroMih Mar 17 '17 at 08:04
  • Considering that it's your answer, I' think you may improve and post it again. So I'd be able to accept and upvote it. Anyway, thank you. – Jaumzera Mar 17 '17 at 12:37
0

You should extract EJB interfaces from EarSample-ejb.jar module and put them into separate jar file EarSample-common.jar. Such archive should be placed in lib folder inside EarSample, so it is reachable from both modules.

Structure should looks like:

EarSample
  EarSample-ejb.jar
  EarSample-web.war
  /lib/EarSample-common.jar

The reason behind that is compliance with JSR standars, where in general EAR modules should have separate classloaders (which is by default not restricted in Glassfish or JBoss/Wildfly).

If you will extract mentioned EJB interfaces to separate maven module and add that artifact to ejb and web module as compile scope dependencies, your solution will work across all JavaEE 6/7 servers.

iskramac
  • 868
  • 6
  • 14