JohnIdol
JohnIdol

Reputation: 50097

How to run java program from cmd line with classpath and native libraries?

Ok I give up - I dont have a lot of xp running java from cmd line and I've been at this for a while, tried endless combinations and I am just frustrated so here we go.

I need to run a simple java app (with dependencies on a bunch of jars that then depend on some native libraries) from cmd line - I am in the bin folder when I try to run the following:

java -Djava.library.path="../lib" -cp ../jar;. MyMainClass

No matter the order (i understand the order counts!) this does not work, with different errors.

For example the version I have pasted above gives me a list of the cmd line params followed by:

-bash: myMainClass: No such file or directory

but MyMainClass.class is there in the bin folder from which I am running the stuff.

If I try this instead:

java -Djava.library.path="../lib" AlphaHHKernel_Tuning_Test -cp ../jar;.

I get:

Exception in thread "main" java.lang.NoClassDefFoundError: MyMainClass
Caused by: java.lang.ClassNotFoundException: MyMainClass
    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)
-bash: .: filename argument required
.: usage: . filename [arguments]

I'd like to understand how those attributes are supposed to be used (and get it to work in the process).

Upvotes: 4

Views: 6793

Answers (1)

jcomeau_ictx
jcomeau_ictx

Reputation: 38432

in Unix specify classpath with a : delimiter, not ; as in Windows: -cp ../jar:.

Also, you need to specify each jarfile, not just give it a directory full of jars.

Upvotes: 2

Related Questions