Last active
February 14, 2018 10:45
-
-
Save rmorenobello/9483fcb15bee0dd3d6b7 to your computer and use it in GitHub Desktop.
Set and Retrieve system (JVM) and environment (OS) variables in java and groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Java System properties | |
// ======================= | |
// http://docs.oracle.com/javase/tutorial/essential/environment/properties.html | |
// http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html | |
/* | |
Key Meaning | |
================ | |
"file.separator" Character that separates components of a file path. This is "/" on UNIX and "\" on Windows. | |
"java.class.path" Path used to find directories and JAR archives containing class files. Elements of the class path are separated by a platform-specific character specified in the path.separator property. | |
"java.home" Installation directory for Java Runtime Environment (JRE) | |
"java.vendor" JRE vendor name | |
"java.vendor.url" JRE vendor URL | |
"java.version" JRE version number | |
"line.separator" Sequence used by operating system to separate lines in text files | |
"os.arch" Operating system architecture | |
"os.name" Operating system name | |
"os.version" Operating system version | |
"path.separator" Path separator character used in java.class.path | |
"user.dir" User working directory // where the user os the OS was when launching this jvm, not where the java file executed was. | |
"user.home" User home directory // In Windows: e.g. Users/rmoreno | |
"user.name" User account name | |
// http://stackoverflow.com/questions/8098564/is-it-possible-to-specify-java-system-properties-when-running-groovy-from-comman | |
/* | |
System properties are set on the java and groovy command line (CLI) using the | |
java -Dpropertyname=value appName | |
syntax. | |
They can also be added at runtime using | |
System.setProperty(name, value) | |
or via the various | |
System.getProperties().load() | |
methods. | |
System.getProperties() | |
lists all java system properties, and those set from command line will be there, | |
but there's no way to distinguish those from the other properties added by the system. | |
Note that you can also set system properties with the environment variable JAVA_TOOL_OPTIONS | |
*/ | |
// Directory of execution (not whee the java file is): | |
String workingDir = System.getProperty("user.dir"); | |
// or | |
String currentDir = new File(".").getAbsolutePath(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment