Reputation: 101
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
Upvotes: 0
Views: 1249
Reputation: 718826
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:
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.
Upvotes: 1
Reputation: 5591
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
Upvotes: 0