views:

38

answers:

2

Hi everybody.

We've been using WAS 6.1 so far to deploy our web apps. Now we need to migrate to an economics-savvy Tomcat + OpenEJB solution. The OpenEJB 3.1.2 container is plugged into Tomcat 6.18, no standalone OpenEJB server here.

So here I am, trying to deploy my EJB 2.1 objects into OpenEJB...

My problem is that the EJBs code requires external .jar libraries, and I don't know where to put them so that they are actually taken into account into the container's classpath. It works fine into catalina.home/lib, so it does into openejb.home/lib. But still I'd rather find out a way to package the EJBs so that they are easy deployed with their linked .jar dropped right into place to be used by the OpenEJB container.

It can include building up an .ear or a .jar with the right descriptor files... Any solution that works is good enough for me.

Can possibly anyone help?

+2  A: 

Ear Approach

You can just drop it into the Tomcat webapps/ directory and it will be picked up.

Example ear (valid):

myapplication.ear
  lib/
  lib/libraryOne.jar
  lib/libraryTwo.jar
  redEjbs.jar
  blueEjbs.jar

Common mistake (invalid):

myapplication.ear
  libraryOne.jar  (err. not a javaee module)
  libraryTwo.jar  (err. not a javaee module)
  redEjbs.jar
  blueEjbs.jar

Only Java EE modules are allowed at the root. These are EJB jars, .war files, Connector .rar files and Application Client jars. Prior to Java EE 5, libraries had to be explicitly listed in an application.xml file. Java EE 5 and forward they can be added to a lib/ directory and be understood to be just plain jars as opposed to a Java EE module.

Collapsed EAR approach

In OpenEJB/Tomcat you can put all your libraries into the war file and be free of the ear concept. This is now part of Java EE 6.

mywebapp.war
  WEB-INF/lib/libraryOne.jar
  WEB-INF/lib/libraryTwo.jar
  WEB-INF/lib/redEjbs.jar
  WEB-INF/lib/blueEjbs.jar

Common mistake, including specs:

mywebapp.war
  WEB-INF/lib/javax.ejb.jar   (err. clashes with the related system library)
  WEB-INF/lib/libraryOne.jar
  WEB-INF/lib/libraryTwo.jar
  WEB-INF/lib/redEjbs.jar
  WEB-INF/lib/blueEjbs.jar

Doesn't sound like that is the issue, but adding for completeness.

Common mistake, broken dependencies:

tomcat/lib/libraryTwo.jar

mywebapp.war
  WEB-INF/lib/libraryOne.jar
  WEB-INF/lib/redEjbs.jar
  WEB-INF/lib/blueEjbs.jar

The above is not invalid from a spec perspective and is impossible for the server to detect, but still can lead to apps not loading correctly. If libraryTwo.jar needs classes in libraryOne.jar then this app will never work as the Tomcat "lib" classloader cannot see classes from the "webapp" classloader, so classes from libraryTwo.jar will never successfully load. Unfortunately, the vm will almost never say the actual class that was missing and instead will report the first class in the chain of events that lead to needing a class that was missing. This is almost always a bean or servlet class.

David Blevins
havent tried this but sounds good. +1
JoseK
Nope, won't work... My EJB relies on a class that's in another .jar. I've tried'n'tried to put that .jar into several spots with no luck: At the .ear's root, into the .war's root, into the .war's WEB-INF/lib folder... When I launch the Tomcat server I keep on having that 'java.lang.NoClassDefFoundError: Could not fully load class: eu.partecis.proxya.ejb.autorisation.UcAutorisationBean due to:EvtAutorisationRechercheBean in classLoader: (yadayada)' exception.
Julian
Putting third-party libs at the root of an ear or war isn't valid. The WEB-INF/lib should have worked provided your ejb jar was in that same WEB-INF/lib dir. Will expand the answer to show some hypothetical examples. If you could expand the question to show all the actual jars you're working with, that would be great.
David Blevins
A: 

Thanks David. I tried all of the above, but still no luck. The Collapsed EAR approach wouldn't work for me I guess, as I far as I know Tomcat 6.0.18 doesn't comply to the J2EE 6 specs. Maybe I'm wrong , but I tried and it didn't work anyway. So back to the standard EAR approach.

My EAR is organized exactly as described in your very first example. One Ejb jar, two library jars in /lib, and that's it. Tomcat still can't instanciate my EJB because the EJB class relates to an unreachable class from Library Jar Two.

I simplified my application.xml file so that it only declares one single EJB:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ...>
<application>
  <display-name>ProxyaEAR</display-name>
  <module id="EjbModule">
     <ejb>ProxyaEJB.jar</ejb>
  </module>
</application>

Any other thoughts??

Julian
The examples in the other post didn't have a descriptor. If you have a descriptor then you have to list all your jars explicitly with <module><java>myLibrary.jar</java></module> for each third-party library.
David Blevins