简体   繁体   中英

How to add custom Java command-line options?

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

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?

您可以通过使用诸如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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM