Reputation: 618
So I would like to build my maven project with
mvn clean package
But once I try to run my built jar file in target folder like
java -jar app-1.0-SNAPSHOT.jar
It shows error:
Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: net/sourceforge/jdatepicker/DateModel at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.privateGetMethodRecursive(Class.java:3048) at java.lang.Class.getMethod0(Class.java:3018) at java.lang.Class.getMethod(Class.java:1784) at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526) Caused by: java.lang.ClassNotFoundException: net.sourceforge.jdatepicker.DateModel at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 7 more
Pom DataPicker dependency:
<!-- https://mvnrepository.com/artifact/net.sourceforge.jdatepicker/jdatepicker -->
<dependency>
<groupId>net.sourceforge.jdatepicker</groupId>
<artifactId>jdatepicker</artifactId>
<version>1.3.2</version>
</dependency>
Why even though dependency was added, exception occurs?
Upvotes: 2
Views: 1435
Reputation: 751
try adding maven plugin so that it copies all your dependencies with the jar file and it does not have to look any further. Do this by adding:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals><goal>copy-dependencies</goal></goals>
</execution>
</executions>
</plugin>
Upvotes: 0
Reputation: 3305
try delete and redownload the jar in your local maven repo.
If your are using idea, try update local repo in the maven setting.
Upvotes: 2
Reputation: 4224
You need to ensure all your dependencies are available to java runtime by adding them to your classpath. Adding a dependency in pom will help only in compiling and packaging the project.
Upvotes: 1