File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# java_study
22java study
3+
Original file line number Diff line number Diff line change 1+ import org .apache .commons .cli .*;
2+
3+ public class CommandLineParserTest {
4+ public static void main (String [] args ) throws ParseException {
5+ Options options = new Options ();
6+
7+ options .addOption (Option .builder ().longOpt ("host" )
8+ .desc ("smtp server host" )
9+ .hasArg ()
10+ .build ());
11+
12+ options .addOption (Option .builder ().longOpt ("port" )
13+ .desc ("smtp server port" )
14+ .hasArg ()
15+ .build ());
16+
17+ options .addOption (Option .builder ().longOpt ("from" )
18+ .desc ("from address" )
19+ .hasArg ()
20+ .build ());
21+
22+ options .addOption (Option .builder ().longOpt ("to" )
23+ .desc ("to address" )
24+ .hasArg ()
25+ .build ());
26+
27+ CommandLineParser parser = new DefaultParser ();
28+
29+ CommandLine line = parser .parse (options , args );
30+
31+ String host = line .getOptionValue ("host" );
32+ String port = line .getOptionValue ("port" );
33+ String from = line .getOptionValue ("from" );
34+ String to = line .getOptionValue ("to" );
35+
36+ System .out .println (host );
37+ System .out .println (port );
38+ System .out .println (from );
39+ System .out .println (to );
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments