简体   繁体   中英

Exception in thread “main” java.lang.NoClassDefFoundError from JAR

i'm trying to run a jar executable from a shell file. the path of my jar :

/home/flussi/xmlEncoder/encoder.jar

but I always get this error:

    Exception in thread "main" java.lang.NoClassDefFoundError: smaf.encoder.Encoder
   at java.lang.Class.initializeClass(libgcj.so.7rh)
Caused by: java.lang.ClassNotFoundException: java.nio.file.LinkOption not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/home/flussi/xmlEncoder/encoder.jar], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
   at java.net.URLClassLoader.findClass(libgcj.so.7rh)
   at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
   at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
   at java.lang.Class.initializeClass(libgcj.so.7rh)

shell command

java -jar /home/flussi/xmlEncoder/encoder.jar

There is evidence in the stacktrace that you are trying to use the GCJ tool chain to run that JAR file. (And the evidence in your comment below confirms this.)

This is the real problem.

Unfortunately, development of GCJ stalled before they completed support for Java 1.5. And it looks like you are trying to run a JAR file that depends on a Java 1.7 class ( java.nio.file.LinkOption )

My recommendation:

  • uninstall the GCJ java packages that have been installed
  • install OpenJDK Java 8 (1.8) packages or later 1 from your package manager or download and install Java 8 or later RPMs from the Oracle site.

If you don't manage the machine, get the managers to do it. Or try to run the JAR file somewhere else.

It would most likely require a significant rewrite of the application to make it work on GCJ. And it would be wasted effort, since GCJ is effectively a dead Java platform.


1 - Java 7 would work, but is was EOLed a couple of years ago.

Hi Best way to run a java application is to set CLASS_PATH and PATH variable first. If your current jar file depends on external jar files you will face lots of problem. Better set your path variable like below and run the application:-

 #!/usr/bin/ksh
 export PATH=/usr/java/bin:$PATH
 # =/usr/java/bin is your java bin folder

 #set environment variable CP with all the jar libraries
 CP=/home/flussi/xmlEncoder/encoder.jar 
 CP=${CP}:/other/jar/somejar.jar

 java -Xmx256M -classpath "$CP" "com.myproj.Example"

This is com.myproj.Example your java class file inside encoder.jar where you have declared public static void main

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM