Reputation: 1136
I plan to run a java class like
java -cp myjar.jar MyClass
myjar.jar will have a manifest file with classpath entry in it.
Is it a valid use case? I have a doubt since I have only seen usage of manifest when using java -jar myjar.jar
Upvotes: 0
Views: 305
Reputation: 719109
You cannot use -cp
(or the CLASSPATH
enviromment variable) together with -jar
. If you need to specify a classpath to make an executable JAR file work, you can specify a Class-Path
attribute in the JAR file's manifest.
On the other hand, the Class-Path
attribute in a JAR file manifest is only used for classes loaded from the JAR file itself. (But it is not restricted to use with -jar
option.)
For more details, refer to the JAR file specification and How classes are found.
Upvotes: 1