Forums Register Login

[EclipseLink] How do I export a JPA Project on Eclipse properly?

+Pie Number of slices to send: Send
Hi guys.

I'm starting my studies on J2EE and I have a problem. Can you help me out?

I have two projects in my workspace, a dynamic web project and a JPA project.
My first project depends on the second. I created classes in the web project that uses the entities and utility classes from the JPA project and whenever I execute them as Java Application, everything works fine. The problem appeared when I tried to use the JPA project's classes in a Servlet. Initially it was related to the fact that the Web Container (Tomcat 7) wasn't finding the classes. I exported my JPA project as a .jar file and moved it to the container's lib folder. Then the original problem was solved but another one appeared:

Servlet.service() for servlet TestServlet threw exception
java.lang.NoClassDefFoundError: Could not initialize class eyra.db.EMFactory


The EMFactory is a utility class that creates a EntityManagerFactory. This is its code:



Can someone please tell what is wrong or if there is a easier way to integrate a Eclipse's JPA Project into a Dynamic Web Project?
+Pie Number of slices to send: Send
The errors seems to indicate that you do not have the persistence.jar and eclipselink.jar on Tomcat's classpath. Try adding these and any other dependencies you have.
+Pie Number of slices to send: Send
I did just like you told me and it worked just fine.

Thanks a lot James.
Take care.
And then we all jump out and yell "surprise! we got you this tiny ad!"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2321 times.
Similar Threads
Appropiate place for creating and closing EntityManagerFactory in Application Managed EntityManager
static methods in Servlet
Hibernate JPA - java.lang.NoClassDefFoundError: javax/persistence/Persistence
EntityManager managed by application
How to create a Template for EntityManager in a WebApplication
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 21:20:34.