0

I have the following set of Java EE 6 applications deployed under JBoss 6:

  • a common JAR with an EJB remote interface
  • 1st WAR-Application with the implementation of that EJB remote interface
  • 2nd WAR-Application with a POJO using the EJB remote interface (@EJB MyRemoteInterface remoteBean;)
  • both WARs have a Maven dependeny with scope provided to the common JAR (not included as JAR within the WAR's lib)

Now, all applications builds fine and the WARs are able to use other common classes from the JAR. But during deployment, I get the error, that the remote interface can't be injected.

So, what is the correct way to deal with the need of sharing the interface class file between the 2 WARs? Do I have to include it as a JAR in WEB-INF/lib in order to make injection work or should it be sufficient to have it deployed?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96

1 Answers1

0

The way of doing this in Java EE 6 is by including the common dependencies in the lib folder of the .ear file.

You can configure the location of this folder in the final .ear via Maven:

<plugin>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.5</version>
    <configuration>
            <defaultLibBundleDir>/lib</defaultLibBundleDir>
        <version>5</version>
...
</plugin>
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
  • Maybe I haven't made myself clear enough - until now, I did not want to bundle the common jar to the WARs (not EAR by the way), since they also contain entities and the persistence unit which I don't want to deploy twice. It works fine with the entities and other helper classes, only the EJB references couldn't be injected, allthough during compile the remote interface class file is visible to the WAR application. So my question is, should it be possible to use an injected remote interface when putting this in a separately deployed JAR or does it have to be within the WARs lib? – Alexander Rühl Aug 02 '11 at 06:41
  • For some reason I assumed you have an ear file where all your wars live, my apologies. I believe the right and straightforward way of doing this is by bundling everything in an ear though as I explain above. Is something preventing you from using an .ear file? – Gonzalo Garcia Lasurtegui Aug 02 '11 at 08:42
  • Well, since JEE 6 you can use the simpler WAR packaging and that's what I did. But I think, the question is independent of the package format, it's just if it's possible to inject something which is deployed as a separate JAR. – Alexander Rühl Aug 02 '11 at 09:23
  • Well, the thing is, your EJB might not be visible from your war, this is why I suggested tweaking the deployment strategy. It is definitely possible to inject something that is in a separate jar - in my current project we have an ear which contains a war that access some interfaces located in a jar that is within the lib folder of the ear. – Gonzalo Garcia Lasurtegui Aug 02 '11 at 12:52