Friday, May 21, 2010

Where is that EntityManagerFactory?

Ok so how much do you hate this error:

java.lang.NoClassDefFoundError: Ljavax/persistence/EntityManagerFactory;

Yeah, on a scale of 1 to 10 I'd rank that one about a 12. You're using Eclipse Ganymede, you've checked your Java build path and there are your jars. (Mine are in a User Library I named Eclipselink) You've checked the /bin folder in your Tomcat and there they are. You go to run your app and

KABOOM

EntityManagerFactory eludes you and your application.

By this point much of your hair may be in clumps on the floor around your chair, much to the disgust of the weekly cleaning crew. People are avoiding your desk at all costs because you're radiating frustration like the outer layers of a star going nova and still no solution presents itself.

And now for the solution:

Eclipse knows you want to use those particular jars, but it may have forgotten where they are. In the Project Explorer view expand your user library and right click your persistence jar. Select Properties. In the new window that pops up the dominant feature will be a text field labeled "Location path:" and if it's empty, BINGO that's your problem.

Click the "External File..." button and browse to the actual jar. Click "OK." Do this for each of the jars in your user library while you're at it.

Don't worry, the hair will grow back.

No comments:

Post a Comment