Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java args like linux args

Tags:

java

arguments

I want to pass arguments to a java application but like linux application style.

The main method in java uses an String array for all parameters. In linux, most applications accepts parameters like: ls -l --color

-l for to output in list style

--color is for colorize output

I want to find an piece of code to parse the String array of main method like linux application.

I want to do something like this: java -jar myapp.jar -d arg1 --arg2

I can make it but I have no time. So, if somebody have some piece of code to do that, better.

like image 372
jotapdiez Avatar asked May 06 '11 14:05

jotapdiez


People also ask

What is a args in Java?

String[] argsIt stores Java command-line arguments and is an array of type java.lang.String class.

What is Arg 0 in Java?

In Java, args[0] is the first command-line argument to the program, and the name of the program itself is not available.)

What is String [] args in Java?

String[] args means an array of sequence of characters (Strings) that are passed to the "main" function. This happens when a program is executed. Example when you execute a Java program via the command line: java MyProgram This is just a test.


1 Answers

You have to parse parameters manually or use http://commons.apache.org/cli/

like image 61
Marcin Avatar answered Sep 28 '22 12:09

Marcin