I *think* because you created them all with "D" and so it only kept the
last one. I think tobdo what you want you would call create with
"DnodeName" for example.

Why do you want this at all? Why not just let the JVM parse the properties
from the cmd line?

Bill-
On Dec 24, 2011 12:44 AM, "LvXiaoyi" <[email protected]> wrote:

>
>
>
>
> Hi,
> I want to use CLI (version 1.2) to parse Java like properties,
> ie. java -DnodeName=MyServer -DnodeIp=10.1.2.2 -DnodePort=1003
>
> here is my test code:
> Option helpOp = new Option("h", "command line help");
>
> Option nodeNameOp = OptionBuilder.withArgName( "nodeName=value" )
>        .hasArgs(2)
>        .withValueSeparator()
>        .withDescription( "the server name" )
>        .create( "D" );
>
> Option nodeIpOp =  OptionBuilder.withArgName( "nodeIp=value" )
>        .hasArgs(2)
>        .withValueSeparator()
>        .withDescription( "server ip" )
>        .create( "D" );
>
> Option nodePortOp =  OptionBuilder.withArgName( "nodePort=value" )
>        .hasArgs(2)
>        .withValueSeparator()
>        .withDescription( "server port" )
>        .create( "D" );
>
> Options cmdOptions = new Options();
> cmdOptions.addOption(helpOp);
> cmdOptions.addOption(nodeNameOp);
> cmdOptions.addOption(nodeIpOp);
> cmdOptions.addOption(nodePortOp);
>
>
> HelpFormatter helpFormatter = new HelpFormatter();
> helpFormatter.printHelp("command line help", cmdOptions);
>
> and here is the output:
> usage: command line help
>  -D <nodePort=value>   server port
>  -h                    command line help
>
> Why the help displays only "NodePort"?
>
> Could anybody give me an example code to use CLI for Java properties?
>
> Thanks
>
> Joey Lv
>
> 12/24/2011
>
>
>
>

Reply via email to