Clashsoft
Clashsoft

Reputation: 11882

Launch jar with custom command line program

Suppose I have some folder in a directory:

- MyApp
  - lib
    - myapp.jar

The location of the MyApp directory is supposed to be stored in an environment variable, like APP_HOME. I would like to add a bin folder that contains two commmand-line executables that launch the java program, one for Windows and one for Unix-based OSs. I already know that one file would just be called myapp and modified with chmod +x, and the Windows one would be named myapp.bat.

What I am unsure about is what the contents of these files would be. As said, both would run the jar file with a custom command line command whose arguments are passed to the main method, as shown below:

>myapp -debug key=value moreargs...

EDIT: How would I go about creating this environment variable, from Java code?

Upvotes: 1

Views: 199

Answers (1)

M A
M A

Reputation: 72844

You can pass command line arguments to the executable by adding $* at the end of the command in the Unix shell script, and %* for the Windows batch file:

java -jar $APP_HOME/lib/myapp.jar $*

Upvotes: 1

Related Questions