[ACCEPTED]-Java: how to import a jar file from command line-classpath
You could run it without the
-jar command line 4 argument if you happen to know the name 3 of the main class you wish to run:
java -classpath .;myjar.jar;lib/referenced-class.jar my.package.MainClass
If perchance 2 you are using linux, you should use ":" instead 1 of ";" in the classpath.
If you're running a jar file with
java -jar, the 7
-classpath argument is ignored. You need to set the classpath 6 in the manifest file of your jar, like so:
Class-Path: jar1-name jar2-name directory-name/jar3-name
See 5 the Java tutorials: Adding Classes to the JAR File's Classpath.
Edit: I see you already 4 tried setting the class path in the manifest, but 3 are you sure you used the correct syntax? If 2 you skip the '
:' after "
Class-Path" like 1 you showed, it would not work.
java -cp "your_jar.jar:lib/referenced_jar.jar" com.your.main.Main
If you are on windows, you should use 1
; instead of
you can try to export as "Runnable jar" in 3 eclipse. I have also problems, when i export 2 as "jar", but i have never problems when 1 i export as "Runnable jar".
More Related questions