Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run jar file with command line arguments [duplicate]

Tags:

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

like image 990
Mario Avatar asked Jan 07 '12 15:01

Mario


People also ask

How can I run a JAR file in command prompt but with arguments?

Run a Nonexecutable JAR with Arguments To run an application in a nonexecutable JAR file, we have to use -cp option instead of -jar. We'll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …]


1 Answers

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]; 
like image 170
Rajesh Pantula Avatar answered Sep 30 '22 13:09

Rajesh Pantula