[java] Run jar file with command line arguments

How can I run a jar file in command prompt and pass arguments to it.

ie: "test.jar -get" would be entered in command prompt/terminal

This question is related to java jar

The answer is


For the question

How can i run a jar file in command prompt but with arguments

.

To pass arguments to the jar file at the time of execution

java -jar myjar.jar arg1 arg2

In the main() method of "Main-Class" [mentioned in the manifest.mft file]of your JAR file. you can retrieve them like this:

String arg1 = args[0];
String arg2 = args[1];