My application uses String str = System.getProperty("key","default");
which always returns default because i am not able to set the key-value pair in the properties file.
I tried setting it in deployment.properties file located in users->appdata->locallow->sun->java>deployment and also directly putting key=value in runtime parameter in java control panel but not working.
Please help me to set it correctly or if there exist a different properties file where these values is to be set, kindly share the path ? I google it but couldn't find.Thanks in Advance
Edit: We use jeety server for deployment.And we have many properties file bundled with our souce code.
System class, we see that the system properties are held in a private instance variable called props, and its values are filled by a native method called initProperties .
properties file that resides in the /QIBM/UserData/Java400 directory. Properties that you set in the /YourUserHome/SystemDefault. properties file affect only the following specific Java virtual machines: JVMs that you start without specifying a different user.
System. getProperty(String key) method returns a string containing the value of the property. If the property does not exist, this version of getProperty returns null. This is based on key – value pair as mentioned in the table given below.
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.
The Values are set using Native code in runtime. Its set inside the System.c, and a function called Java_java_lang_System_initProperties
Snippet
JNIEXPORT jobject JNICALL
Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
{
char buf[128];
java_props_t *sprops = GetJavaProperties(env);
jmethodID putID = (*env)->GetMethodID(env,
(*env)->GetObjectClass(env, props),
"put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
jmethodID removeID = (*env)->GetMethodID(env,
(*env)->GetObjectClass(env, props),
"remove",
"(Ljava/lang/Object;)Ljava/lang/Object;");
jmethodID getPropID = (*env)->GetMethodID(env,
(*env)->GetObjectClass(env, props),
"getProperty",
"(Ljava/lang/String;)Ljava/lang/String;");
jobject ret = NULL;
jstring jVMVal = NULL;
if (sprops == NULL || putID == NULL ) return NULL;
PUTPROP(props, "java.specification.version",
JDK_MAJOR_VERSION "." JDK_MINOR_VERSION);
PUTPROP(props, "java.specification.name",
"Java Platform API Specification");
PUTPROP(props, "java.specification.vendor",
JAVA_SPECIFICATION_VENDOR);
PUTPROP(props, "java.version", RELEASE);
PUTPROP(props, "java.vendor", VENDOR);
PUTPROP(props, "java.vendor.url", VENDOR_URL);
PUTPROP(props, "java.vendor.url.bug", VENDOR_URL_BUG);
.......
.......
.......
Well, the System.getProperty(String)
returns properties that relate to the global system of a JVM. Here you can find a list of available properties.
If you want to load a custom file of properties, you should load this file in your own properties object of which you can find an example here. You should keep this Properties
object seperate of the system properties. You should never just load your custom properties into the system properties. (You could do this via System.setProperties(Properties)
.) This is like defining global variables which is a sign of poor program design.
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