Where to add JVM parameter nojce in weblogic?
In my experience we have always added JVM parameters to the
${WL_HOME}/bin/setDomainEnv.sh
script as an extra property under the
$EXTRA_JAVA_PROPERTIES
variable.
How to set a java system property so that it is effective whenever I start JVM without adding it to the command line arguments
You can set set environment variable JAVA_TOOL_OPTIONS
in your OS. All Java tools (java, javac, ..) will pick this variable up and use it. So you could e.g. use
SET JAVA_TOOL_OPTIONS=-Dsun.locale.formatasdefault=true
I use this to force a specific locale for each JVM.
But this only works if your application is started through the Java tools. If it is e.g. started from a C program that calls the jvm DLL this won't be used.
Edit: I just tested it, and it seems JAVA_TOOLS_OPTIONS is also picked up when the DLLs are started (verified with a Swing application that uses WinRun4J as a launcher)
See: http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/envvars.html
How to specify JVM Parameters inside Spring Boot Project when executed with init.d
As of Spring boot 2.0, you can set the inlinedConfScript
property of the build plugin. You can now reference a file that includes the appending or overwriting the JAVA_OPTS variable before the application starts. More details can be found in the Spring Documentation.
Java VM argument type -D and --
The syntax for the java
command is:
java [options] mainclass [args ...]
There are alternatives where you specify something other than mainclass
, but the important part is that options
comes before that part and args
comes after that part, i.e. they cannot be intermingled.
The java
command supports many options, one of which is:
-Dproperty=value
Sets a system property value. The property variable is a string with no spaces that represents the name of the property. The value variable is a string that represents the value of the property. If value is a string with spaces, then enclose it in quotation marks (for example
-Dfoo="foo bar"
).
So that it handled by the Java runtime.
args
is a list of program arguments, and is handled by Java code, which means they can be anything. It's up to the code processing them to decide where they mean.
A Spring program uses a SpringApplication
method to process those arguments. See your main
method:
Register a
CommandLinePropertySource
to expose command line arguments as Spring properties.
See the javadoc for more detail.
Spring also has a PropertySource
for making Java System Properties available as Spring Environment properties, which is why Spring can use properties defined either of these commands:
java -Dfoo=bar mainclass
java mainclass --foo=bar
How to pass 'unsafe' arguments to the JVM of a Java Webstart application
There are several options to pass JVM arguments to webstart.
- Through JNLP file.
- Through the JAVA_TOOL_OPTIONS environment variable.
- Through the deployment settings on the local computer.
- Through the javaws command (I was unable to get this to work).
Note that I have included links to the java 8 version of this documentation. All of these ideas are supported and documented in other Java versions, however sometimes they work a tiny bit different, or have slightly changed restrictions.
Through JNLP file.
The JNLP supports many JVM arguments through the JNLP file. Some can be done though direct settings, such as initial-heap-size
and max-heap-size
. For other settings java-vm-args
can be used.
The JNLP File Syntax documentation lists some supported java-vm-args for 'this version' however it is unsure if that is the version 1.4+
of the example, or JRE 8. I know some unlisted settings are actually supported, such as -XX:MaxGCPauseMillis
and activating the G1 garbage collector. You can make a JNLP and then use jinfo -flag MaxGCPauseMillis <pid>
to test if a setting has been correctly propagated.
This is the preferred method, because it does not require any direct control of the JVM. The down-side is that only supports specific parameters that are considered 'safe'.
Through the JAVA_TOOL_OPTIONS environment variable
When you start Java Webstart by using the javaws
command, you can use the JAVA_TOOL_OPTIONS
to set any parameter you want on all JVM started from that environment.
So in Linux you can do to set an unsupported parameter:
export JAVA_TOOL_OPTIONS=-XX:SoftRefLRUPolicyMSPerMB=2000
javaws <my jnlp>
Note that this will affect all java applications ran with this system variable. So setting this for all users, or a specific user should be done with great care. Setting this only for a single application as the example above is much safer.
The advantage of this solution is that you can pass any parameter you want. The downside is that it requires a specific way of launching the application, or a very broad setting. It also requires control over the client system.
Through the deployment settings on the local computer
You can also pass JVM arguments by changing the deployment settings of the JVM. This can be done through the Java Control Panel, which allows you to set default runtime settings.
If you want to automate these settings you can use the deployment properties file. Unfortunately the JRE specific section of this file is undocumented. Manually it is very easy to adapt this file:
deployment.javaws.jre.0.args=-XX\:SoftRefLRUPolicyMSPerMB\=2000
When automating this file, you have to watch very carefully that it contains these settings for all detected JVMs, so you have to be sure to change the correct one. Also this will be used for all Webstart and applets on your system.
Through the javaws command (I was unable to get this to work)
There should be another way (besides the JAVA_TOOL_OPTIONS
method) to change the parameters using the command line. The javaws documentation lists the -J
option to pass arguments to the JVM, for example by running your JNLP as follows:
javaws -J-XX:SoftRefLRUPolicyMSPerMB=2000 <my jnlp>
However I have not been able to get this to actually set the JVM parameters.
Related Topics
Hadoop "Unable to Load Native-Hadoop Library For Your Platform" Warning
Run a Java Application as a Service on Linux
How to Set Java_Home in Linux For All Users
Downloading Java Jdk on Linux Via Wget Is Shown License Page Instead
Add a Complex Image in the Panel, With Buttons Around It in One Customized User Interface
What Is the Reason Behind "Non-Static Method Cannot Be Referenced from a Static Context"
Java Generics Type Erasure: When and What Happens
Relation Between Memory Host and Memory Arguments Xms and Xmx from Java
Distinguishing Between Java Threads and Os Threads
Java Refuses to Start - Could Not Reserve Enough Space For Object Heap
Why Use Getters and Setters/Accessors
Sort a Map≪Key, Value≫ by Values
Int Division: Why Is the Result of 1/3 == 0
Selenium: How to Stop Geckodriver Process Impacting Pc Memory, Without Calling Driver.Quit()
:: (Double Colon) Operator in Java 8