Correct way to pass the argument for the main method in this class in command line java

Viewed 526

Can arguments for a class be passed the following way?

java cs123.Learn -mode train -algorithm even_odd -model_file speech.even_odd.model -data speech.train -task classification

Here, cs123 is the package within which the different java files and their compiled versions are located. I have already compiled the .java files using the following command

javac -cp commons-cli-1.2.jar cs123\*.java

To make things clear, the structure of the .java and .jar files are

lib
|--cs362
|    |--all the java files including Learn.java
|--commons-cli-1.2.jar

I am running the command prompt from the lib folder. What worries me is that from java documentation and other sources the format for passing arguments is simply an array of strings and for options it can be seen from java documentation too. Using the above run time java execution, I get the

java.lang.ClassNotFoundException: org.apache.commons.cli.OptionBuilder

but if I execute,

java -cp commons-cli-1.2.jar cs123.Learn -mode train -algorithm even_odd -model_file speech.even_odd.model -data speech.train -task classification

I get the following error

Unrecognized option: -mode
Error: Could not create the Java Virtual Machine
Error: A fatal exception has occured. Program will exit.

I understand that java tries to associate anything with a - associated with it as a predefined option, -mode not being the one it recognizes. but at the same time the .jar file is there to do it's job. For research purposes, the commons-cli-1.2.jar file is associated with several methods, two of them being commons/cli/Option and commons/cli/OptionBuilder.

I am having to do this because the instruction is to run the program using

java cs123.Learn -mode train -algorithm even_odd -model_file speech.even_odd.model -data speech.train -task classification
2 Answers
Related