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开发者_JS百科
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
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?
You can make it easier to use arguments by using something such as args4j.
I'm pretty sure you can do this. Atleast in Sun's implementation of java 1.6.
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 ;
.
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.
精彩评论