Linux java system properties

How to set system property?

I am trying to follow this instruction for running gate embedded. It says: «System property gate.home should be set to the gate installation directory.» (http://gate.ac.uk/wiki/code-repository/) How do I do this? Also when I try to run the example code of EmbeddedAnnie I get the following error: ( I don’t know if it is related or not ).

Initialising GATE. GATE home system property ("gate.home") not set. Attempting to guess. Using "C:\Program Files (x86)\GATE-6.0" as GATE Home. If this is not correct please set it manually using the -Dgate.home option in yo ur start-up script Using C:\Program Files (x86)\GATE-6.0 as GATE home Using C:\Program Files (x86)\GATE-6.0\plugins as installed plug-ins directory. Using C:\Program Files (x86)\GATE-6.0\gate.xml as site configuration file. Using C:\Users\UNST\gate.xml as user configuration file Using C:\Users\UNST\gate.session as user session file Exception in thread "main" java.lang.NoClassDefFoundError: gate/creole/gazetteer /AbstractGazetteer at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14 1) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:296) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:296) at gate.util.GateClassLoader.loadClass(GateClassLoader.java:63) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at gate.creole.CreoleAnnotationHandler.processAnnotationsForResource(Cre oleAnnotationHandler.java:193) at gate.creole.CreoleAnnotationHandler.processAnnotations(CreoleAnnotati onHandler.java:169) at gate.creole.CreoleAnnotationHandler.processAnnotations(CreoleAnnotati onHandler.java:173) at gate.creole.CreoleAnnotationHandler.processAnnotations(CreoleAnnotati onHandler.java:173) at gate.creole.CreoleAnnotationHandler.processAnnotations(CreoleAnnotati onHandler.java:157) at gate.creole.CreoleRegisterImpl.processFullCreoleXmlTree(CreoleRegiste rImpl.java:358) at gate.creole.CreoleRegisterImpl.parseDirectory(CreoleRegisterImpl.java :341) at gate.creole.CreoleRegisterImpl.registerDirectories(CreoleRegisterImpl .java:306) at gate.Gate.initCreoleRepositories(Gate.java:449) at gate.Gate.init(Gate.java:230) at StandAloneAnnie.main(StandAloneAnnie.java:69) Caused by: java.lang.ClassNotFoundException: gate.creole.gazetteer.AbstractGazet teer at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) . 27 more 

Источник

Читайте также:  Run object file in linux

What Is This Post About ?

In this post, we will see how to check the full list of system properties of JVM and how to change the value of the properties from the command line.

Full List of JVM System Properties

If you use Oracle JDK or OpenJDK, by using the following command, you can check he full list of system properties of JVM and their current value.

java -XshowSettings:properties -version

-version is used just to avoid displaying the usage of java command which is displayed if no standard option is specified.

The result will be something like this.

Property settings: awt.toolkit = sun.lwawt.macosx.LWCToolkit file.encoding = UTF-8 file.encoding.pkg = sun.io file.separator = / ftp.nonProxyHosts = local|*.local|169.254/16|*.169.254/16 gopherProxySet = false http.nonProxyHosts = local|*.local|169.254/16|*.169.254/16 java.awt.graphicsenv = sun.awt.CGraphicsEnvironment java.awt.printerjob = sun.lwawt.macosx.CPrinterJob java.class.path = . java.class.version = 52.0 java.endorsed.dirs = /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/endorsed java.ext.dirs = /Users/user_name/Library/Java/Extensions /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/ext /Library/Java/Extensions /Network/Library/Java/Extensions /System/Library/Java/Extensions /usr/lib/java java.home = /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre java.io.tmpdir = /var/folders/5g/jgf0bss53813w2js3pm8n18c0000gn/T/ java.library.path = /Users/user_name/Library/Java/Extensions /Library/Java/Extensions /Network/Library/Java/Extensions /System/Library/Java/Extensions /usr/lib/java . java.runtime.name = Java(TM) SE Runtime Environment java.runtime.version = 1.8.0_181-b13 java.specification.name = Java Platform API Specification java.specification.vendor = Oracle Corporation java.specification.version = 1.8 java.vendor = Oracle Corporation java.vendor.url = http://java.oracle.com/ java.vendor.url.bug = http://bugreport.sun.com/bugreport/ java.version = 1.8.0_181 java.vm.info = mixed mode java.vm.name = Java HotSpot(TM) 64-Bit Server VM java.vm.specification.name = Java Virtual Machine Specification java.vm.specification.vendor = Oracle Corporation java.vm.specification.version = 1.8 java.vm.vendor = Oracle Corporation java.vm.version = 25.181-b13 line.separator = \n os.arch = x86_64 os.name = Mac OS X os.version = 10.13.6 path.separator = : socksNonProxyHosts = local|*.local|169.254/16|*.169.254/16 sun.arch.data.model = 64 sun.boot.class.path = /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/resources.jar /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/rt.jar /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/sunrsasign.jar /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/jsse.jar /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/jce.jar /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/charsets.jar /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/jfr.jar /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/classes sun.boot.library.path = /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib sun.cpu.endian = little sun.cpu.isalist = sun.io.unicode.encoding = UnicodeBig sun.java.launcher = SUN_STANDARD sun.jnu.encoding = UTF-8 sun.management.compiler = HotSpot 64-Bit Tiered Compilers sun.os.patch.level = unknown user.country = JP user.dir = /Users/user_name/Desktop user.home = /Users/user_name user.language = en user.name = user_name user.timezone = java version "1.8.0_181" Java(TM) SE Runtime Environment (build 1.8.0_181-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

How to Set Value to the System Properties

You can set the value to the system properties by adding JVM options like this.

Читайте также:  Close established connections linux

For example, if you want to make JVM to search /home/tomcat/lib for shared libraries, you can specify it as follows.

java -Djava.library.path=/home/tomcat/lib .

The setting is not permanently applied but only applied to the JVM you launch by the command. Note that the default value is overwritten.

Источник

Reading Java system properties from command line

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

Do you want to be able to distinguish between default system properties and those set/overridden via the command line?

You may wish to read System Properties and The Extension Mechanism Architecture if you haven’t already, or you might just leap right in and try System.getProperty(«java.ext.dirs») .

4 Answers 4

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.

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:

For this use case, you could use:

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

jcmd VM.flags jcmd VM.command_line jcmd GC.run 

It seems like VM.system_properties only prints «well known» properties. Is there a way to view properties that the user has created?

You can use jps a tool that comes with the jdk. It can print out the system properties that were passed to a java process.

For example: On my system eclipse is running and

6632 -Dosgi.requiredJavaVersion=1.6 -Xms1024m -Xmx2048m -XX:MaxPermSize=512m 

jps is located in JDK_HOME/bin

Читайте также:  Linux обновление через командную строку

If you want all the properties use the jinfo tool that is also located in JDK_HOME/bin . To use it you must know the process id of the java process you want to get information from. E.g.

This tool also prints out the java.ext.dirs

If you need defaults that your JVM will initially have set unless overridden, use:

java -XshowSettings:properties -version 

This is helpful if you don’t have a Java application already running, thus no pid to pass to one of the other commands.

If you are seeking the properties of a JVM already running that has properties set via default or set explicitly by command, then use the pid for that JVM found via jps with the jcmd or jinfo commands as listed in answers above.

Before jcmd times one can use JMX management connection from VisualVM. It is UI app so you have to expose JMX port from your remote headless servers to the that info.

JMX settings might look like:

JAVA_OPT="$JAVA_OPT -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT -Dcom.sun.management.jmxremote.port=$JMX_PORT -Dcom.sun.management.jmxremote.host=localhost -Dcom.sun.management.jmxremote.local.only=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=localhost" 

Источник

Оцените статью
Adblock
detector