Arguments ignored in Java Jar

I am running the following code on Ubuntu 10.10 using OpenJDK 1.6.0_18:

package mypkg; public class MyTest { public static void main(final String[] args) { System.out.println(args.length + " argument(s)"); for (final String arg : args) { System.out.println(arg); } } } 

After compiling in the Jar, I am completely puzzled why executing the following command from the terminal returns 0 argument(s) :

java -jar mytest.jar is a test

This is my interpretation of Java docs that says:

java [options] -jar file.jar [argument ...]

I almost feel like I'm entering the wrong command with the wrong command. What gives?

Edit: MANIFEST.MF contains:

 Manifest-Version 1.0 Created-By: 1.6.0_18 (Sun Microsystems Inc.) Main-Class: mypkg.Starter Class-Path: . 
+4
source share
3 answers

View the contents of your META-INF/MANIFEST.MF file; make sure your Main-Class using the correct class.

+3
source

The manifest indicates mkpkg.MyTest as the main class file, and the file you published is named mypkg.MyTest .

You also specify the class path "." in your manifest, which is superfluous at best, but probably leads to the problem you are seeing (since you probably got a directory named mkpkg in your local directory).

+2
source

If you knew your main class, you can do this without the -jar option.

 java -classpath .:my_jar_file.jar; package.MainClass [arguments] 

This works for me on Debian Lenny.

+1
source

All Articles