1

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?

pierre tautou
  • 807
  • 2
  • 20
  • 37

3 Answers3

0

Try adding: javaee-api-5.0-2.jar to your project.

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
0

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

Community
  • 1
  • 1
Xavi López
  • 27,550
  • 11
  • 97
  • 161
  • Yes I checked that, 1) I check in maven site: http://search.maven.org/#search%7Cga%7C4%7Cfc%3Ajavax.persistence.EntityNotFoundException 2) By unzip this package. – pierre tautou Sep 27 '11 at 15:32
  • I doesn't usage **org.hibernate:hibernate-annotations:3.3.1.GA** I usage **org.hibernate:hibernate-commons-annotations:3.2.0.Final** – pierre tautou Sep 27 '11 at 15:38
  • Yes I can reference to it from my IDE. Next I tried extract the content of jar, which Intellij build for me and then I extract the **org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final** jar file. I browse to it content and found this class. – pierre tautou Sep 27 '11 at 15:53
  • I create own **EntityNotFoundException** class, and now I have the same error but with another class, the class is now: **org.springframework.context.ApplicationContext** – pierre tautou Sep 28 '11 at 08:09
  • 1
    @pierretautou What kind of executable jar are you producing? Does it have nested jars with the dependencies (library jars inside your app jar). If this is the case, take a look at the related question I posted in this answer, and also take a look at [One-Jar](http://one-jar.sourceforge.net/index.php) and other tools mentioned in the related question. – Xavi López Sep 28 '11 at 08:19
  • I actually have three maven modules: persistence, domain, app. The dependencies are: persistence using domain and app using persistence. So I trying to create jar from app, which using persistence and domain dependencies. Each from this dependencies using some maven dependencies, which all of this I include in jar. – pierre tautou Sep 28 '11 at 09:57
  • @pierretautou What I'm trying to tell you is that if your executable JAR `app.jar` has nested JARs (i.e. `hibernate-jpa-2.0-api-1.0.1.Final.jar` is inside `app.jar`), it won't be possible to locate any of `hibernate-jpa-2.0-api-1.0.1.Final.jar`'s classes at runtime unless you write your own classloader, or use a tool that provides it, such as [One-Jar](http://one-jar.sourceforge.net) – Xavi López Sep 28 '11 at 10:04
0

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.

spikeheap
  • 3,827
  • 1
  • 32
  • 47