Got a java class with main method, say com.foo.Bar
. But there are two optional vm(system) arguments for this class, say key1, key2.
Created a batch & shell shell scripts to call the above programs as below respectively.
Contents of Batch File(barRunner.cmd
)
@echo off
set CLASSPATH=/bla/;/bla/
java -cp %CLASSPATH% com.foo.Bar %*
Contents of Shell script(barRunner.sh
)
export CLASSPATH=/bla/:/bla/
java -cp $CLASSPATH com.foo.Bar $@
Now user calling in the below manner, but vm arguments cannot be read by Bar class
barRunner.cmd -Dkey1=value1
or
./barRunner.sh -Dkey2=value2 -Dkey1=value1
Suspect that the vm argument is passed after the class.
How to pass the vm arguments so that they are available before class name?
EDIT:
Have already tried changing script as below and it worked. But the issue if the class has program arguments.
java -cp %CLASSPATH% %* com.foo.Bar
Also aware of JAVA_OPTS, but it is a bit tedious for naive users; I mean, multiple commands to be run(set JAVA_OPTS in one command & and call the script in another line) and hesitant to use that way.
So thought of checking with forum if there is better way to achieve both vm & program arguments in single line and both args are optional.