Wednesday, April 23, 2014

Passing System Property Resource from JNLP file to Java Webstart

Java have changed the way how system properties are passed from jnlp file to the javaws (Java Webstart).

Since the update of Java to 1.7.0_45, getting the system property using the following code will no longer work:
System.getProperty("myproperty");
There are two solution for this issue:
1. You need to sign the jnlp files

     See this link for instruction:
     http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/signedJNLP.html

2. Update the JNLP files to have additional prefix in the resource string variable

     Example: For log4j.configuration, here is what you need to do:
<resources>
<j2se version="1.7"/>
<jar href="lib/log4j-1.2.16.jar"/>
<property name="jnlp.log4j.configuration" value="file:///C:/log4j.properties "/>
</resources>

---------------------------------------------------------------------------------------------------------------------------------

I haven't tried the #1 yet because it is quite complex. Option #2 is the quickest solution. However, you need to update your program to also add a prefix when reading the system property.
System.getProperty("jnlp.myproperty");
For backward compatibility, it is recommended to always check for the old variable before using the new variable.

       String property = System.getProperty("jnlp.myproperty");
       if (property.isEmpty())
       {
             property = System.getProperty("myproperty");
       }

Feel free comment if you still encounter any issue related to this.

Credits to:
https://community.oracle.com/message/11239354

No comments:

Post a Comment

AOL Directory Sumbit Url
Submit Site to Yahoo