Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass Java command line options in a separate file?

Is there any way of launching Oracle's Java.exe and have it take its command line options from a text file on Windows?

What I'd like to be able to do is something like this:

java.exe -optionsFile=myOptionsFile.txt MyClass

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

All of the options must be present when Java.exe is run as it is the target of a memory debugging tool called VMMap. VMMap allows you to launch a .exe and attach to it in order to debug native heap issues. In this case, I cannot generate the command line args at runtime or have another process launch java.exe for me.

like image 725
Mark Douglas Avatar asked Nov 07 '22 17:11

Mark Douglas


1 Answers

You could use xargs.

Given a file, arguments.in, with the following contents:

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

Invoked like so:

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

Produces this output (i.e. the same output as if you invoked 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: this assumes you are either on a *nix OS or are using Cygwin (or a simulator emulator such as GOW).

like image 153
glytching Avatar answered Nov 14 '22 23:11

glytching