I have problem with creating executable jar file. I creating the jar file by Intellij idea X artifacts. But when I try to execute this jar, it gave me an error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/EntityNotFoundException
Caused by: java.lang.ClassNotFoundException: javax.persistence.EntityNotFoundException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at开发者_开发问答 java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I check which package contains this class and I found it in this maven dependency:
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
</dependency>
I check if the Intellij add this jar to my executable jar and I found it there. So have someone any Idea where the problem is?
Indeed, hibernate-jpa-2.0-api
contains this class.
It might be a classpath issue. Are you including required jar libraries in your jar? Can your app access other application provided jars at runtime? You may find the answers to this question useful: Classpath including JAR within a JAR
Try adding: javaee-api-5.0-2.jar to your project.
The JPA libs are a separate external download from Oracle. You may need to download them separately and install them into your local Maven repo.
You should also be specifying a version in your dependency XML.
精彩评论