Get OpenJPA jars loaded by tomcat

abladapt
abladapt used Ask the Experts™
on
Hi
I have a spring mvc app which uses openjpa 2.1.1 as its persistence framework. It is developed as a Maven project in STS, and runs locally on vFaric TC Server (Tomcat 7).

When we first deployed the war to Websphere 8.5, we encountered classloader conflicts with the following 3 openjpa jars which were in our war file:

geronimo-jpa_2.0_spec-1.1.jar
geronimo-jta_1.1_spec-1.1.1.jar
validation-api-1.0.0.GA.jar

Removing these from the war and deferring to Websphere's bundled openjpa worked fine, so I changed the openjpa POM dependency scope from 'compile' to 'provided' (so that these jars would not be packaged into the war file).

Since Tomcat 7 is not JEE compliant, I placed the 3 jars in Tomcat\lib (also tried the vfabric-tc-server lib - which wraps tomcat), but the JPA classes were not visible by the app at startup (noclassdeffound exceptions in console).

I also tried adding the jars to the server classpath from 'launch configuration' within STS - no luck there either.

Is there a class loader order that needs to be set somewhere in Tomcat such that JPA loads before the app?

What I need is a build that will work when deployed to either Tomcat or Websphere.

Any help will be much appreciated.

Thanks
Jim
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2018
Commented:
Since Tomcat 7 is not JEE compliant, I placed the 3 jars in Tomcat\lib (also tried the vfabric-tc-server lib - which wraps tomcat), but the JPA classes were not visible by the app at startup (noclassdeffound exceptions in console).

Are you sure? By putting the jar files in the lib folder they should be available to both Tomcat internal classes and to all web applications. Are you sure that the NoClassDefFoundError is about the jpa files?
Commented:
Hi, Thanks for responding. You are correct. The NoClassDefFoundError was referring to a JPA class, but NOT one of those from the 3 jars I included. I ran mvn tree and found that the entire chain of JPA dependencies was:

openjpa-2.1.1.jar
commons-lang-2.4.jar
commons-collections-3.2.1.jar
geronimo-jta_1.1_spec-1.1.1.jar
geronimo-jpa_2.0_spec-1.1.jar

I also needed to add:

serp-1.12.0.jar

I originally included the validation-api-1.0.0.GA.jar in tomcat/lib as well because it had to be removed from the war to get websphere working, but placing this in tomcat/lib caused a "javax.validation.ValidationException: Unable to find default provider" so I took it out, meaning just the above 6 jars needed to be added.

Author

Commented:
Solved myself following guidance from girionis

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial