How to get VM arguments from inside of Java application?
With this code you can get the JVM arguments:
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
...
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimeMxBean.getInputArguments();
Is there a Java API to get the VM arguments?
This method will give you all the command line arguments RuntimeMXBean.getInputArguments()
How to read the -Dserver.ref VM argument
This should work:
final String ref = System.getProperty("server.ref");
ref
should be equal to "test"
.
Getting the parameters of a running JVM
You can use jps like:
jps -lvm
It prints something like:
4050 com.intellij.idea.Main -Xms128m -Xmx512m -XX:MaxPermSize=250m -ea -Xbootclasspath/a:../lib/boot.jar -Djb.restart.code=88
4667 sun.tools.jps.Jps -lvm -Dapplication.home=/opt/java/jdk1.6.0_22 -Xms8m
Loading VM arguments from a file when running a Java application on Windows
The best solution I've found today is to create the cmd file as follows:
@echo off
set LIST=
for /F %%k in (vmarguments.txt) DO call :concat %%k
echo %LIST%
java %LIST% VMArgumentsFromFile
:concat
set LIST=%LIST% %1
goto :eof
This approach requires that the vm arguments in the text file are surrounded in quotes and on their own lines.
This is based off the answer at: How to concatenate strings in a Windows batch file?
How can I specify the default JVM arguments for programs I run from eclipse?
Yes, right click the project. Click Run as
then Run Configurations
. You can change the parameters passed to the JVM in the Arguments
tab in the VM Arguments
box.
That configuration can then be used as the default when running the project.
Specifying JVM arguments when calling a jar file?
Do it like:
java -Xms256m -Xmx512m -Djava.awt.headless=true -jar filename.jar
Related Topics
Java Executors: How to Be Notified, Without Blocking, When a Task Completes
How to Query Xml Using Namespaces in Java with Xpath
Explicit Casting from Super Class to Subclass
How Come Invoking a (Static) Method on a Null Reference Doesn't Throw Nullpointerexception
Preferred Java Way to Ping an Http Url for Availability
Difference Between Paint, Paintcomponent and Paintcomponents in Swing
How to Create an .Exe for a Java Program
Resume Http File Download in Java
How to Use 3Des Encryption/Decryption in Java
Java - Convert Integer to String
Using "Like" Wildcard in Prepared Statement
Java Byte Array to String to Byte Array
Importing Two Classes with Same Name. How to Handle