2

I need to pass parameters to a java application with a double dash, like this:

java -cp "app.jar" package.App --parameter1=arg1 --parameter2=arg2

What is the easiest way to do this in Java?

Thanks in advance!

-----------UPDATE---------

I'm trying to parse commands in a specific format, with a double dash and equals sign to assign value.

My question is a simple and elegant way to do it with some parser. And I believe this question is still unanswered.

WilsonPena
  • 1,451
  • 2
  • 18
  • 37
  • Possible duplicate of [Parsing arguments to a Java command line program](https://stackoverflow.com/questions/7341683/parsing-arguments-to-a-java-command-line-program) – Justin Albano Apr 05 '18 at 11:22
  • It sounds like you're effectively asking for a CLI argument parser - in which case I'd close the question as a request for an external resource recommendation... – Jon Skeet Apr 05 '18 at 15:40
  • I'm asking if there is some standard way to do this. I was requested to format it this way, and thought java had some tool to make this in a simple way. Instead of making my own parser. – WilsonPena Apr 05 '18 at 15:42
  • apache beam sdk in java supports this, as you can `MyOptions options = PipelineOptionsFactory.fromArgs(args).withValidation().as(MyOptions.class);` My options is an interface where getter setters of props are written. – Muhammad Azam Nov 26 '21 at 07:04
  • 1
    I want exact same thing instead of apache beam – Muhammad Azam Nov 26 '21 at 07:12

0 Answers0