How to pass Java command line parameters to a separate file?

Is there a way to start Oracle Java.exe and use its command line options from a text file in Windows?

What I would like to do is something like this:

java.exe -optionsFile=myOptionsFile.txt MyClass 

where 'myOptionsFile.txt' contains a list of standard Java VM parameters, such as "-classpath =" my very long path to classes "and" -Dthis = that ", etc.

All parameters must be present when starting Java.exe, because it is intended for a memory debugging tool called VMMap. VMMap allows you to run .exe and connect to it to debug your own heap problems. In this case, I cannot generate command line arguments at runtime or start another java.exe process for me.

+5
source share
2 answers

You can use xargs .

Given the arguments.in file with the following contents:

 ~/dev/code$ more arguments.in -version 

Called like this:

 ~/dev/code$ cat arguments.in | xargs $JAVA_HOME/bin/java 

Produces this output (i.e. the same output as when calling java -version ):

 java version "1.8.0_51" Java(TM) SE Runtime Environment (build 1.8.0_51-b16) Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode) 

Note: it is assumed that you are either on the * nix operating system, or are using Cygwin (or a simulator emulator, such as GOW ).

0
source

Easy way: -

 yourclassName=JavaClassName java `cat myOptionsFile.txt` $yourclassName 

On windows this should work fine.

 set /p VAR=<myOptionsFile.txt java.exe %VAR% yourclassName 
0
source

Source: https://habr.com/ru/post/1271336/


All Articles