Exception in thread "main" java.lang.NoClassDefFoundError from JAR

Giulio Angioli Source

i'm trying to run a jar executable from a shell file. the path of my 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


answered 7 days ago Stephen C #1

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 later1 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.

answered 7 days ago Abhijit Pritam #2

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:-

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

 #set environment variable CP with all the jar libraries

 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

comments powered by Disqus