Hello Guys I am trying to figure out why i am gettings this error when I am trying to run this API from Shell on my linux System.
[~/public_html/test/]# java -jar jodconverter-cli-2.2.2.jar Amritpal.doc sample.pdf
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli/CommandLineParser
Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.CommandLineParser
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: com.artofsolving.jodconverter.cli.ConvertDocument. Program will exit.
You need to do this in order to include the Apache Commons CLI library in your classpath:
java -cp '.:/path/to/cli.jar' -jar jodconverter-cli-2.2.2.jar x.doc y.pdf
If you're on Windows, use a semicolon ; instead of the colon : in specifying the classpaths.
Because you don't have the dependencies specified in the classpath (The first one being exactly what the error is telling you, the apache.commons.cli library).
You either need to specify them on the command line or in the manifest in that jar.
Related
I have a Java program that uses slf4j-api-1.7.10.jar and slf4j-simple-1.7.10.jar. I have tried to compile it in my Unix shell like so:
javac -cp "$CLASSPATH:.:slf4j-api-1.7.10.jar:slf4j-simple-1.7.10.jar" Test.java
Running java Test results in this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at SystemCommandExecutor.<clinit>(SystemCommandExecutor.java:13)
at Test.main(Test.java:12)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
... 2 more
I am able to run the program in Windows with the two jar dependencies, so I don't believe I need any extra jars. Perhaps I am issuing the wrong command to compile in Unix as I am fairly unfamiliar with the syntax.
Why you don't create a pom.xml for compile it with a maven dependency?
In that case you should include the package for the main class:
javac -classpath external.jar com/yourpackage/yourMainClass.java
Also check your syntax for the slf4j inclusion.
I'm attempting to run Apache Ant for the purpose of compiling OpenGTS. While attempting to run any "ant" command I'm getting the following output:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: org.apache.tools.ant.launch.Launcher. Program will exit.
Previously I was getting a message stating "JAVA_HOME is not defined correctly" and after reading several forum threads, was able to solve that by updating the path:
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk
Another thread stated a "CLASS PATH" issue but if I'm able to run "ant" anywhere in the terminal, wouldn't the path be correct? Thanks in advance.
Make sure to set ANT_HOME to the directory where you installed ant. Refer to Installling Apache Ant.
You need to export ANT_HOME too, just make sure it is installed first on your system
export ANT_HOME="/usr/local/ant";
In my case it was a wrong permission on /opt/ant/lib folder.
I am trying to run a java project from the command line in linux, my project uses two external jar files. The command that i am givin is
java -classpath -jar bin:common-cli-1.2.jar:BuildFrameworkLibrary.jar com.kpit.goa.common.tools.kivibuild.KIVIBuild
where KIVIBuild is the class that contains the main function. But the error that am getting is:
baibhav#baibhav:~/git/KiviBuild/Infra/RepoManagement/BuildManagement/KIVIBuild$ java -classpath bin:common-cli-1.2.jar:BuildFrameworkLibrary.jar com.kpit.goa.common.tools.kivibuild.KIVIBuild
Gives
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.ParseException
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: com.kpit.goa.common.tools.kivibuild.KIVIBuild. Program will exit.
You need a path separator e.g.
bin/common-cli-1.2.jar:BuildFrameworkLibrary.jar
The colon separates paths to individual jar files. e.g. in the above you're referencing the two files
bin/common-cli-1.2.jar
BuildFrameworkLibrary.jar
and also reference the directory containing your compiled classes e.g. if they're in (say) target/classes then use:
target/classes:bin/common-cli-1.2.jar:BuildFrameworkLibrary.jar
(relative to your current working directory)
Use following command
javac -classpath bin/common-cli-1.2.jar:bin/BuildFrameworkLibrary.jar KIVIBuild.java -d .
Do not forget to add dot at the end of command
check is /com/kpit/goa/common/tools/kivibuild/KIVIBuild.class exist or not
if yes run the following command
java -classpath bin/common-cli-1.2.jar:bin/BuildFrameworkLibrary.jar com/kpit/goa/common/tools/kivibuild/KIVIBuild
http://www.linuxheadquarters.com/howto/classpath.shtml
Rather than setting class path every time set it onces in existing classpath variable and just run the java command
I had a homework assignment which is to be done using OpenMp, but I'm not a good c/c++ programmer, so I decided to do it in java using the JOMP API.
Anyway, I have a problem running the hello world program. I did all the steps showing in this link but I'm still getting this error when I try to compile:
java jomp.compiler.Jomp Hello
I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: jomp/compiler/Jomp
Caused by: java.lang.ClassNotFoundException: jomp.compiler.Jomp
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: jomp.compiler.Jomp. Program will exit.
I use ubuntu 11.10 jdk 6
Exception in thread "main" java.lang.NoClassDefFoundError: jomp/compiler/Jomp
In general this exception occurs if jar file is not in runtime classpath. Make sure you have add jomp.jar (Don't know exact jar name, use valid jar) which has jomp/comipler/Jomp class to classpath.
I used ObjectWeb's ASMifier to get a 'HelloDump.java', and added classloader and a main method to load and run a spoofed "HelloWorld".
If I run 'HelloDump.java' in the build tool sbt, everything works fine and outputs "HelloWorld!".
But if I use raw Java, it breaks. 'HelloDump.java' seems to compile OK, but the resulting 'HelloDump.class' is clearly present, yet doesn't seem to be recognized (check the sequence below):
$ julianpeeters#julianpeeters-virtual-machine ~/asm-example $ javac -cp lib/asm-all-4.1.jar HelloDump.java
$ julianpeeters#julianpeeters-virtual-machine ~/asm-example $ ls
DumpLoader.java.bak HelloDump.class.bak Hello.java.bak
Hello.class.bak HelloDump$DynamicClassLoader.class lib
HelloDump.class HelloDump.java README.md
$ julianpeeters#julianpeeters-virtual-machine ~/asm-example $ java -cp lib/asm/all/4.1.jar HelloDump
Exception in thread "main" java.lang.NoClassDefFoundError: HelloDump
Caused by: java.lang.ClassNotFoundException: HelloDump
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: HelloDump. Program will exit.
Explicitly adding . to the classpath doesn't help either.
So why does this work in sbt, but not in raw Java, and how can I fix it?
Thanks, any advice is appreciated,
-Julian
Add . to your CLASSPATH, so your command becomes:
java -cp lib/asm-all-4.1.jar:. HelloDump
The reason the JVM cannot find the class is that it looks only on the classpath and nowhere else.