Reputation: 2444
if I run:
java -jar corpus-tools-0.0.2.jar removeTSfromCorpus
it gives me error:
Failed to parse the trailing argument list: 'removeTSfromCorpus'
However, if I run:
java -cp corpus-tools-0.0.2.jar removeTSfromCorpus
It works seamlessly. scala-library is inlcuded in dependencies(MANIFEST). What is difference in -cp and -jar? I think there should be equal in this case
thanks!
Upvotes: 2
Views: 1112
Reputation: 272297
java -cp jarfile classname
executes classname using the specified classpath (-cp
). Instead of using the -cp
option you could simply rely on the CLASSPATH
variable to determine where java
finds the classes.
java -jar jarfile
will use the specified .jar
file and execute the Main-Class
defined in the .jar
file MANIFEST. This is java's close approximation to a standalone app. The app is packaged in the .jar
file and the MANIFEST specifies the entry point within that .jar
file. See here for more details.
So (to answer your original question!) your first example will run a class specified in the MANIFEST, and that's trying to interpret removeTSFromCorpus
as a command line argument in some fashion. Your second example sets the CLASSPATH to your .jar file and then runs removeTSFromCorpus
as a class.
Upvotes: 5
Reputation: 13416
The -jar
option is trying to execute the static main
method from the main class defined in your jar file, then provides it with the argument removeTSfromCorpus
.
The -cp
option considers you are providing a classpath then trying to run the main
method from the removeTSFromCorpus
class.
Upvotes: 1
Reputation: 24334
When running a JAR the main class and classpath should be specified in the MANIFEST.MF file.
You then just run it like:
java -jar corpus-tools-0.0.2.jar
See:
http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
Extract
If you have an application bundled in a JAR file, you need some way to indicate which class within the JAR file is your application's entry point. You provide this information with the Main-Class header in the manifest, which has the general form:
Main-Class: classname
And
http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
Extract:
You specify classes to include in the Class-Path header field in the manifest file of an applet or application. The Class-Path header takes the following form:
Class-Path: jar1-name jar2-name directory-name/jar3-name
Upvotes: 2