java showSettings implementation/source of information - java

Java -XshowSettings dump the information such as VM setting. Where in the box/system this information configured or what is the source of the setting? Is there any property file ?
java -XshowSettings:all

The information comes from various sources; e.g. command line options, environment variables, values derived from the result of syscalls, default values hard-wired into the JVM executable, and so on.
Is there any property file ?
There are some system properties that are defined by property files in the $JAVA_HOME/cfg tree, but the majority of the properties and other settings come from other places.

Related

what and where is "jdbc.drivers" system property? [duplicate]

What's the difference between system properties System.getProperties() and environment variables System.getenv() in a JVM?
System properties are set on the Java command line using the -Dpropertyname=value syntax. They can also be added at runtime
using System.setProperty(String key, String value) or via the various
System.getProperties().load() methods.
To get a specific system property you can use System.getProperty(String key) or System.getProperty(String key, String def).
Environment variables are set in the OS, e.g. in Linux export HOME=/Users/myusername or on Windows SET WINDIR=C:\Windows etc,
and, unlike properties, may not be set at runtime.
To get a specific environment variable you can use System.getenv(String name).
I think the difference between the two boils down to access. Environment variables are accessible by any process and Java system properties are only accessible by the process they are added to.
Also as Bohemian stated, env variables are set in the OS (however they 'can' be set through Java) and system properties are passed as command line options or set via setProperty().

How to externalize the properties of a jacoco javaagent

I'm trying to get code coverage data from a remote server, so I added a JVM argument:
-javaagent:/opt/jacocoagent.jar=output=tcpserver,port=6300,includes="a pretty long list"
but unfortunately the includes list is too long, that the java command has exceeded the maximum length of our system limits.
Is there any way to specify a external property file so I can put the long "includes list” there?
I've read the jacoco document, it seems when running in "Offline Instrumentation", the jacoco agent will read properties from jacoco-agent.properties if it appears in classpath. But I don't want to use this mode.
Found a solution myself.
When oracle JVM startup, it picks an environment variable JAVA_TOOL_OPTIONS and
the JNI_CreateJavaVM function (in the JNI Invocation API) prepends the
value of the environment variable to the options supplied in its
JavaVMInitArgs argument.
So in my case, I defined:
JAVA_TOOL_OPTIONS=-javaagent:/path/to/jacocoagent.jar=output=tcpserver,address=*,port=6300,includes="a pretty long list"
For details, you can refer to:
https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/envvars002.html

Passing a system property to an executable

Currently, I am trying to pass a system property to an executable in the following format: ./executable -Dvar="value" other parameters, since this is what I've seen people do for java files. I keep getting an error in the executable saying that -Dvar="value" doesn't exist as a parameter. Where am I going wrong? Are system properties exclusive to Java or something?
The -D parameter sets a system property. The system properties can be accessed through System.getProperty("<your parametername>");
A tutorial is given here https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
The -D is consumed by the java runtime (java.exe) and will be invisible to your application on the commandline.

how to set location of jvm crash log files

I need to configure where the jvm crash logs are created. I like the name they have (hs_err_pid.log) but I want them created in an specific folder.
In here you can see that you can use the
-XX:ErrorFile=./hs_err_pid<pid>.log
param to set the FILE created, but if you set this to a folder, so the file is created in that folder with the original naming convention, it does not work, it is ignored.
I have been testing this by crashing jvm 1.6 from this questions, using this:
PathDasher dasher = new PathDasher(null) ;
Anybody knows a way to achieve this?
-XX:ErrorFile=/var/log/java/hs_err_pid%p.log works.
See http://www.oracle.com/technetwork/java/javase/felog-138657.html
The parameter does not allow for environment variables, but you can use environment variables in a launcher script (e.g. .sh or .bat) and the OS will do the substitution. However, this will use the value of the environment variable at the time of starting the JVM and not when the file is written later. Furthermore, environment variables do not work when setting Run properties in Eclipse.
The JVM will not create intermediate directories saving the crash dump. The crash dump will be saved at the default location if the specified folder does not exist.
You have to use this as
java -XX:ErrorFile=/var/log/java/hs_err_pid%p.log -Xbootclasspath/p:. Crash
in command prompt.
Here, Crash is my java file.

How to set system properties through a file with Oracle's JVM

According to Oracle, the only way to set system properties is through command line -D parameters like that :
java -Dmy.prop=value com.package.MyClass
Is it really the only way ? Isn't it possible to create some system.properties file that will contain all these properties, and that would be automagically read when the JVM starts ?
I precise I can have no use of the System.setProperty(String,String) function.[1]
Setting this file through a command line parameter would be fine as well :
java -Fsystem.properties com.package.MyClass
I have searched where I know (and found there is a way with IBM's JVM), but I'm still empty-handed...
[1] : The goal is to set the default Charset, and this is primarily done through the file.encoding property, but only at the VM startup phase. Setting this property in runtime doesn't change the default Charset, and there is also no way to change it 'programmatically'.

Categories