14

I want to add the below parameters to JAVA_TOOL_OPTIONS. Could anyone please help me how to add these?

set JAVA_TOOL_OPTIONS=-Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF8

If i add like above, will it work?

I tried setting the above command but i am not sure whether java picks these two parameters or not?

Experts help would be much appreciated.

1
  • 1
    Trying it is simple. Run a Java tool from the commandline and it will report whether it picked it up.
    – user330315
    Jun 25, 2013 at 10:10

3 Answers 3

13

I tried setting this variable in my windows environment with Java 7 and doing java -version it gives me it set this variable , as shown as follows

C:\Users\ajduke>set JAVA_TOOL_OPTIONS=-Djava.net.preferIPv4Stack=true -Dfile.e
ncoding=UTF8

C:\Users\ajduke>java -version
Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF
8
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b145)
Java HotSpot(TM) Client VM (build 21.0-b15, mixed mode, sharing)
3
  • How can I define this in my java app? I don't want to recommends to all my clients to run above set command!!! Thanks Mar 1, 2014 at 7:13
  • @MohTarvirdi depends on what kinda of application you running? is your app runninng in Tomcat Container, Spring container or Standalone app?
    – ajduke
    Mar 1, 2014 at 15:05
  • Note that there are no quotes (' or " around values of JAVA_TOOL_OPTIONS). I tried to set it up with " first, but as a result all the values have been set to the first property only. Mar 9, 2020 at 13:04
4

Previous answer works for Windows. For unix based environment you should follow these steps:

  1. Edit /etc/profile adding line:

    export JAVA_TOOL_OPTIONS='-Djava.net.preferIPv4Stack=true -Dfile.encoding="UTF-8"'

  2. Run

    source /etc/profile

This will set global environment variable JAVA_TOOL_OPTIONS for all users immediately.

4

In case only the first argument is picked up: DON'T USE QUOTES! Just the arguments:

set JAVA_TOOL_OPTIONS=-Xms128m -Xmx512m

In my case (Windows), only the first argument was picked up and reported to be invalid, since I used

set JAVA_TOOL_OPTIONS="-Xms128m -Xmx512m"

and starting any java app results in:

Picked up JAVA_TOOL_OPTIONS: "-Xms128m -Xmx512m"
Invalid initial heap size: -Xms128m -Xmx512m
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.