Set Java system properties with a configuration file
There is a way to set java.library.path programatically, see this.
The code is a hack to set the sys_path field on the ClassLoader,
System.setProperty( "java.library.path", "/path/to/libs" );
Field fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" );
fieldSysPath.setAccessible( true );
fieldSysPath.set( null, null );
It would be pretty simple to do yourself:
public static void main(String[] args) {
Properties p = new Properties();
p.load(...); // Load the properties from a file in your jar
for (String name : p.stringPropertyNames()) {
String value = p.getProperty(name);
System.setProperty(name, value);
}
}
Use JAVA_TOOL_OPTIONS
environment variable. _JAVA_OPTIONS
may also work, but it's not documented at all. The JAVA_TOOL_OPTIONS
is weakly documented, but here are some links:
- http://www.oracle.com/technetwork/java/javase/envvars-138887.html#gbmsy
- https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/envvars002.html
- https://bugs.openjdk.java.net/browse/JDK-4971166
An example of use:
set JAVA_TOOL_OPTIONS=-Dmy.property=sth
When launching JVM you should see a message:
Picked up JAVA_TOOL_OPTIONS: ...