views:

114

answers:

5

Hi!

I'd like to add custom command-line options to my Java program. Here's an example:

java -cp my.jar package.Main -i input.data -o output.data

How can I achieve this. Currently I only get

JVMJ9VM007E Command-line option unrecognised: -i

Edit: The output of java -version

java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build pap64dev-20080315 (SR7))
IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 AIX ppc64-64 j9vmap6423-20080315 (JIT enabled)
J9VM - 20080314_17962_BHdSMr
JIT  - 20080130_0718ifx2_r8
GC   - 200802_08)
JCL  - 20080314
+1  A: 

I'm pretty sure you can do this. Atleast in Sun's implementation of java 1.6.

Jagat
+3  A: 

I've just tried this on my Windows JVM:

java version "1.5.0" Java(TM) 2 Runtime Environment, Standard Edition (build pwi32devifx-20080907 (SR 8a + IZ29767 + IZ30684 + IZ31214 + IZ31213)) IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223ifx-2008 0811 (JIT enabled) J9VM - 20080809_21892_lHdSMr JIT - 20080620_1845_r8 GC - 200806_19) JCL - 20080907

And as would expect it works just fine. Your error message is the kind of thing I might expect if your command line looked like:

 java -cp my.jar  -i input.data -o output.data package.Main

Are you using any kind of shell wrapper for Java that might re-order the arguments?

djna
Also tried this on IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Linux amd64-64 j9vmxa6423-20081129 (JIT enabled) with a small tool that just dumps the arguments, and it worked just fine. public class Test { public static void main(String... args) { System.out.println(java.util.Arrays.deepToString(args)); } }
ankon
+1  A: 

You can make it easier to use arguments by using something such as args4j.

npsken
That doesn't help if you can't get into the Java runtime to begin with. It's a true statement, but not at all relevant to the actual question.
Mark Peters
+1  A: 

I'm assuming "my.jar" is not your actual classpath. Does your actual classpath have path separators in it (i.e. multiple paths)? If so, are you using the correct one for your system? Remember that *nix systems use : while Windows uses ;.

Mark Peters
A: 

I guess I've found the solution: The problem was that I ran a normal .jar file as if it was an executable .jar with the -jar argument. This seemed to cause the annoyance.

Bernhard V