I have a project (Java application with a main
) that runs fine from within Eclipse but when I export it to a (packed) runnable Jar and try to launch it from the command line with java -jar
I get the following error message:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: java.lang.NoClassDefFoundError: com/github/javafaker/Faker
at jultävlingar2020.Jultävlingar2020.useChrome(Jultävlingar2020.java:154)
at jultävlingar2020.Jultävlingar2020.main(Jultävlingar2020.java:57)
... 5 more
Caused by: java.lang.ClassNotFoundException: com.github.javafaker.Faker
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 7 more
There seems to be a problem with the inclusion of javafaker
but using it works fine within Eclipse.
The project is Gradle-based and in my Project and External dependencies
-folder I have javafaker-1.0.2.jar
.
My build.gradle looks like this:
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:28.2-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
// Selenium
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
// Javafaker
implementation 'com.github.javafaker:javafaker:1.0.2'
}
How do I fix this?