-
Running Java program
I have a program which uses an external library, apfloat.jar.
It compiles and runs in eclipse IDE, but I need to be able to compile and run it from the terminal.
It actually compiles from the terminal when I use the following command:
Code:
javac Generator.java -classpath apfloat.jar
but then I have no idea how to run it, when I use this:
Code:
java Generator -classpath apfloat.jar
I'm getting the following exception:
Code:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apfloat/Apfloat
Caused by: java.lang.ClassNotFoundException: org.apfloat.Apfloat
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could you maybe tell me how can I run this program?
-
Form the directory containing Generator.class and apfloat.jar try changing the order of the arguments:
Code:
java -classpath apfloat.jar Generator
-
I tried it, and now it doesn't find the class "Generator" (and clearly the class is there):
Code:
nataliazon$ ls
Generator.class Generator.java apfloat.jar lib org
nataliazon$
nataliazon$ java -cp apfloat.jar Generator
Exception in thread "main" java.lang.NoClassDefFoundError: Generator
Caused by: java.lang.ClassNotFoundException: Generator
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
-
Sorry, I wasn't thinking (more coffee needed).
You also have to tell the java executable that the current directory is part of the classpath.
Code:
java -cp .:apfloat.jar Generator
"dash c p space dot colon etc"
-
It's working now! Big thanks!
-