I have a property TOOLS_DIR
that i exported in bash
I have the following line in my java file:
String toolsDir = System.getProperty("TOOLS_DIR");
Why is this returning null? is the a compatibility issue with linux or something?
getProperty("path. separator"); The getProperty method returns a string containing the value of the property. If the property does not exist, this version of getProperty returns null.
getProperties() fetches the current properties that JVM on your System gets from your Operating System. The current System properties are returned as Properties object for use by the getProperties() method. If no such set of properties is present, a set of system is first created and then initialized.
The getProperty(String key) method in Java is used to returns the system property denoted by the specified key passed as its argument.It is a method of the java. lang. System Class. where key is the name of the System property.
Environment variables and properties aren't the same thing. If you want to pass in an environment variable as property you have to add the following to your java invocation:
-DTOOLS_DIR=$TOOLS_DIR
Alternatively, you can use System.getEnv()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With