0

I have an application that is opened by the terminal. It loads some data automatically and now I need to be able to use commands such as -new or -min or -help within the terminal with functionalities implemented in my Java code. So I need to define new parameters for my command line (which only work during the runtime of my apllication).

I tried to search it for several hours now but all I get are tips how to run java programs with my command line... So I am pretty stuck right now and hope you can help me out. I am thankfull for every answer.

SilverA
  • 23
  • 1
  • 5
  • Maybe have a look at scanner: https://stackoverflow.com/questions/37582362/how-do-i-get-user-input-when-i-run-my-jar-file-from-command-prompt – s0771416 Nov 18 '17 at 16:28
  • I had a look at the post you showed me there, but I can`t find a connection to my question. I want to know how I can define a new command line command which only works during the runtime of my application. It does not seem to have anythin to do with that. – SilverA Nov 19 '17 at 15:41

1 Answers1

0

All the command line arguments for your program are passed to the main method in that method's only parameter, the string array (typically named args).

You can parse this array manually, or feed it to a library like Getopt to handle all of that for you.

Fahad Sadah
  • 2,368
  • 3
  • 18
  • 27
  • I am not sure if I got this right. Would you mind showing me an example? – SilverA Nov 19 '17 at 12:41
  • For now I think it could look like this: public class *** { public static void main (String[] args) { ..... }} And there you would put your parameters into the args? How would that look like for parameters like --name, --min, --max? I just have no experience with giving parameters to my main method like that... – SilverA Nov 19 '17 at 12:47