java - Run a JAR file from the command line and specify classpath -
i've compiled jar file , specified main-class in manifest (i used eclipse export function). dependencies in directory labeled lib
. can't seem straight answer on how execute jar file while specifying should use lib/*
classpath.
i've tried:
]$ java -jar -cp .:lib/* myjar.jar ]$ java -cp .:lib/* -jar myjar.jar ]$ java -cp .:lib/* com.somepackage.subpackage.main
etc...
each gives error saying:
error: not find or load main class ....
or gives noclassdeffounderror
indicating libraries not being found.
i tried remaking jar file , included lib
directory , contents, still no dice...
how can execute jar file command line , specify classpath use?
when specify -jar
-cp
parameter ignored.
from the documentation:
when use option, jar file source of user classes, , other user class path settings ignored.
you cannot "include" needed jar files jar file (you need extract contents , put .class files jar file)
you have 2 options:
- include jar files
lib
directory manifest (you can use relative paths there) - specify (including jar) on commandline using
-cp
:
java -cp myjar.jar:lib/* com.somepackage.subpackage.main
Comments
Post a Comment