Arguments ignored in Java Jar
I'm running the following code on Ubuntu 10.10, using OpenJDK 1.6.0_18:
package mypkg;
public class MyTest {
public static void main(fi开发者_运维知识库nal String[] args) {
System.out.println(args.length + " argument(s)");
for (final String arg : args) {
System.out.println(arg);
}
}
}
After compiling it into a Jar, I'm completely puzzled why executing the following command from the terminal returns 0 argument(s)
:
java -jar mytest.jar this is a test
This is my interpretation of the Java docs, stating:
java [ options ] -jar file.jar [ argument ... ]
I almost have the feeling that I'm entering a wrong command in the terminal. What gives?
Edit: the MANIFEST.MF contains:
Manifest-Version 1.0
Created-By: 1.6.0_18 (Sun Microsystems Inc.)
Main-Class: mypkg.Starter
Class-Path: .
Have a look at the contents of your META-INF/MANIFEST.MF
file; make sure your Main-Class
is using the correct class.
Your manifest specifies mkpkg.MyTest
as the main class file, while the file you've actually posted has the name mypkg.MyTest
.
Also, you specify a Classpath of "." in your manifest, which is superfluous at best, but probably leads to the problem you see (as you've probably got a directory named mkpkg
in your local directory).
If you knew your main class you can do it without the -jar option.
java -classpath .:my_jar_file.jar; package.MainClass [arguments]
This is working for me on Debian Lenny.
精彩评论