4

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

1

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

7 Comments

mmm ... now at least I get the same error with both versions if using: -cp ../jar/:. but not sure what that means
see latest edit, it took me awhile to register the more blatant omission!
thanks man, you rock - that worked (but only with -cp before the main class). It's kind of weird that you cant point to the folder ... but that's what I get for not reading 'the instructions' I guess
generally in Unix the options come before the arguments, and the main class is the argument in this case.
you could with some trickery, something like: -cp $(echo ../*.jar | tr ' ' ':'):. because the shell expands wildcard matches with spaces, and Java wants its classpath with colons
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.