4

I am trying to execute a jar file. It needs both program arguments and the jvm arguments. Do we need to do something different while passing the command line parameters in order for it to be able to differentiate them, or it will be handled automatically?

Currently I am using eclipse IDE, so I can configure it. However it will be finally run using command line only. Please let me know if something needs to be done differently.

1
  • can you post some code for your question Commented Jun 23, 2015 at 13:01

2 Answers 2

6

Well, the JVM arguments are typed before using '-D', then after the jar file you'll type your program arguments:

java -Djvm_argument1=XXX -Djvm_argument2=YYY -jar myjar.jar my_argument1 my_argument2
Sign up to request clarification or add additional context in comments.

4 Comments

any argument after the filename are treated as program arguments and before the filename are treated as jvm args?
Before are JVM if they are prefixed with -D after your .jar or .class they are arguments of your program
what about memory related args like -Xmx, should they be prefixed as -DXmx, because I encounter error when doing so, just using -Xmx works, and specifying them after the filename makes them treated as program arguments since I can access them inside the agrs[]
Arguments prefixed with -D can be accessed as an environment variable within your program, other like -Xmx and so on, are exclusive to the JVM
0

I assume you're using java -jar file.jar? It's the same as if you used java MainClass. JVM arguments like -ea, -cp, -classpath, -X..., -D..., etc. are targeted to the VM while all other arguments are targeted to your app.

3 Comments

are they automatically targeted to program or we have to pass them after the jar only while doing "java -jar file.jar"?
java -jar file.jar [VM args as described above] arg1 arg2 ... -- The app will get "arg1", "arg2", ... in args from public static void main(String args[]). I assume this is what you were going for?
yes.. I just wanted to know if the sequence of the arguments.. not the sequence of args1 args2, but the overall sequence of vm args and program args... does it matter... But I guess ur comment suggests that It does not :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.