Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Java system properties from command line

Is there a better way to print system properties from command line? As we can set the property e.g.

 java  -D<name>=<value>  //set a system property 

Without writing a class to do that?

If not possible, why is it not possible/feasible/good to do that from the command line ?

like image 758
sakhunzai Avatar asked Oct 20 '14 06:10

sakhunzai


People also ask

What is system properties in Java?

Java™ system properties determine the environment in which you run your Java programs. They are similar to system values or environment variables in IBM® i. Starting an instance of a Java virtual machine (JVM) sets the values for the system properties that affect that JVM.

How do I print system properties in Linux?

1. How to View Linux System Information. To know only the system name, you can use the uname command without any switch that will print system information or the uname -s command will print the kernel name of your system. To view your network hostname, use the '-n' switch with the uname command as shown.

How do I find system properties in Java?

In Java, you can use System. getProperties() to get all the system properties.


1 Answers

You can use the -XshowSettings flag in the Hotspot JVM version 1.7 and up (not supported in 1.6):

java -XshowSettings:properties -version 

OpenJDK has had support for this flag since late 2010.

Seen in http://marxsoftware.blogspot.de/2016/02/hotspot-jvm-XshowSettings.html

EDIT 14 Dec 2016

The Oracle JVM ships with the tool jcmd which allows you to see the flags present in a running JVM. See:

https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html

For this use case, you could use:

jcmd <pid> VM.system_properties 

But there are also many other useful commands. For example:

jcmd <pid> VM.flags jcmd <pid> VM.command_line jcmd <pid> GC.run  
like image 141
AdrianRM Avatar answered Sep 28 '22 04:09

AdrianRM