When running java hwai.Main
from directory target/classes
, I get an error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/Persistence
at hwai.Main.main(Main.java:17)
Caused by: java.lang.ClassNotFoundException: javax.persistence.Persistence
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
...
I get the same error when I'm running java hwai.Main
from directory target/test1/WEB-INF/classes
This is my project structure after running mvn package glassfish:redeploy
:
├── pom.xml
├── src
│ └── main
│ ├── java
│ │ ├── hwai
│ │ │ ├── helloWorld.java
│ │ │ ├── helloWorldResource.java
│ │ │ ├── Main.java
│ │ │ ├── StudentPOJO.java
│ │ │ ├── StudentRest.java
│ │ │ └── Todo.java
│ │ └── META-INF
│ │ └── persistence.xml
│ └── webapp
│ ├── index.html
│ └── WEB-INF
│ └── web.xml
└── target
├── classes
│ └── hwai
│ ├── helloWorld.class
│ ├── helloWorldResource.class
│ ├── Main.class
│ ├── StudentPOJO.class
│ ├── StudentRest.class
│ └── Todo.class
├── generated-sources
│ └── annotations
├── maven-archiver
│ └── pom.properties
├── maven-status
│ └── maven-compiler-plugin
│ └── compile
│ └── default-compile
│ ├── createdFiles.lst
│ └── inputFiles.lst
├── test1
│ ├── index.html
│ ├── META-INF
│ └── WEB-INF
│ ├── classes
│ │ └── hwai
│ │ ├── helloWorld.class
│ │ ├── helloWorldResource.class
│ │ ├── Main.class
│ │ ├── StudentPOJO.class
│ │ ├── StudentRest.class
│ │ └── Todo.class
│ ├── lib
│ │ ├── commonj.sdo-2.1.1.jar
│ │ ├── eclipselink-2.7.0.jar
│ │ ├── javax.json-1.0.4.jar
│ │ ├── javax.persistence-2.0.0.jar
│ │ └── validation-api-1.1.0.Final.jar
│ └── web.xml
└── test1.war
Searching the internet, I found Eclipse Warnings: class javax.persistence.* not found and java.lang.NoClassDefFoundError: javax/persistence/Persistence, but neither helped me. I'm quite a javaee newbie.
pom.xml
contains among others
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
The import
- statement in Main.java is
import javax.persistence.Persistence;