Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Apache CLI Help

807598Aug 11 2006
For some reason, the Apache CLI package will not read more than one command from the command line

If I give this command:
java -cp FTPCleanup.jar com.echostar.ittools.FTPCleanup -loggerconfig logger.development.properties -ftpconfig ftpcleanup.development.properties

If gives this error:
Parsing the command line failed. Reason: -ftpconfig


Now if I reverse the options on the command line, then the error will be on the "loggerconfig" argument. How can I get both options to be read in? The documentation is giving me a headache while trying to understand what I am doing wrong.

The code is below.

			Option ftpconfig = OptionBuilder.withArgName( "ftpconfig").hasArg().isRequired().withDescription("Path to the FTPCleanup properties file").create("ftpconfig"); 
			Option loggerconfig = OptionBuilder.withArgName( "loggerconfig").hasArg().isRequired().withDescription("Path to the logger properties file").create("loggerconfig"); 
				
			options.addOption( ftpconfig );
			options.addOption( loggerconfig );
			CommandLineParser parser = new BasicParser();
			org.apache.commons.cli.CommandLine line = null;
//			CommandLineParser parser = new GnuParser();
			try {
				line = parser.parse(options, args);
				if ( line.hasOption( "ftpconfig" ) ) {
					System.out.println("ftpconfig is " + line.getOptionValue("ftpconfig"));
				}
				else {
					System.out.println("ftpconfig not defined.");
				}
				if ( line.hasOption( "loggerconfig" ) ) {
					System.out.println("loggerconfig is " + line.getOptionValue("loggerconfig") );
				}
				else {
					System.out.println("loggerconfig not defined.");
				}
	
			}
		    catch( org.apache.commons.cli.ParseException exp ) {
		        System.err.println( "Parsing the command line failed.  Reason: " + exp.getMessage() );
		        return false;
		    }
		}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 8 2006
Added on Aug 11 2006
0 comments
230 views