You could run it without the -jar
command line argument if you happen to know the name of the main class you wish to run:
java -classpath .;myjar.jar;lib/referenced-class.jar my.package.MainClass
If perchance you are using linux, you should use ":" instead of ";" in the classpath.
If you're running a jar file with java -jar
, the -classpath
argument is ignored. You need to set the classpath in the manifest file of your jar, like so:
Class-Path: jar1-name jar2-name directory-name/jar3-name
See the Java tutorials: Adding Classes to the JAR File's Classpath.
Edit: I see you already tried setting the class path in the manifest, but are you sure you used the correct syntax? If you skip the ':
' after "Class-Path
" like you showed, it would not work.
try
java -cp "your_jar.jar:lib/referenced_jar.jar" com.your.main.Main
If you are on windows, you should use ;
instead of :
you can try to export as "Runnable jar" in eclipse. I have also problems, when i export as "jar", but i have never problems when i export as "Runnable jar".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With