I'm working on a java project and trying to run a jar file. I'm getting the error:
Exception in thread "main" java.lang.NoClassDefFoundError
Most of the other threads I've read, said that it was because I needed to use the -classpath
option. However, I've tried implementing this a couple of ways and I'm getting the same error, still.
The last way that I tried to implement the -classpath
option and execute the jar file is shown below.
java -classpath "/full/file/path/file.jar" -jar file.jar
Please let me know what I'm doing wrong!
-jar
is for self-contained jars. https://stackoverflow.com/a/18413058/20394 explains that -classpath
is ignored when -jar
is specified. Just do -jar /full/file/path/file.jar
if it is a self-contained jar. If it's not, you will need to use -classpath
and make sure all its runtime dependencies are available via that classpath.
If you haven't already, it might be worth learning to use a build system like mvn
or bazel
to manage the class path for you, or to try running your class through an IDE like Eclipse.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.