Java Web Start
Wednesday, 29. March 2006, 09:03:52
I decided to test it out with a small test application that just shows an empty JFrame, JWSTest.java:
package jwstest;
import javax.swing.JFrame;
public class JWSTest {
public static void main(String[] args)
{
JFrame f = new JFrame();
f.setSize(100, 100);
f.setTitle("TestFrame");
f.setVisible(true);
}
}
Netbeans creates the Jar file for me so I won't go through that.
Place the Jar file on your web server and create JWSTest.jnlp file in the same location:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0"
codebase="http://my.opera.com/Mr%20Green/homes/dist"
href="JWSTest.jnlp">
<information>
<title>TestFrame Demo</title>
<vendor>GreenSoft AS</vendor>
<offline-allowed/>
</information>
<resources>
<jar href="JWSTest.jar"/>
<j2se version="1.3+"
href="http://java.sun.com/products/autodl/j2se"/>
</resources>
<application-desc main-class="jwstest.JWSTest"/>
</jnlp>
Now you can direct Opera to http://my.opera.com/Mr%20Green/homes/dist/JWSTest.jnlp to launch the application. This runs in the sandbox so you don't need to fear havoc by clicking the link. You need Java installed.
Netbeans / Matisse layout manager
Now if you try to do the same with a jar file from an existing project created in Netbeans, and try to run it via JWS it just refuses to load. It seems like the application starts but never gets displayed, the javaw process is running but no application is visible.
This has to do with the swing-layout-1.0.jar file used when building GUI's with Matisse/Netbeans. I must be included as a reference in the jnlp file and placed on the server or the application never shows.
For more information on Netbeans/JWS look below.
To enable Java Web Start for Netbeans applications go here:
http://www.netbeans.org/kb/articles/matisse-jaws.html
Security / All permissions
By default, applications launched via JWS runs in a sandbox environment, just lika an Applet would. As an example you won't be able to write to the file-system or create connections to hosts other than the one where the application came from. If you want your app to have the same permissions as a "native/local" java application all the JAR files in the application needs to be signed. Even the swing-layout-1.0.jar file and other third party libraries must be signed. See my previous post on "Signing jar files"
After signing the Jar files you have to insert the following into the jnlp file to actually get all permissions:
<security> <all-permissions/> </security>
If the following dialog box appears you've successfully signed your application:

The warning says the certificate is invalid since it is not from a Certificate Authority. Since that costs money I won't bother with that.
One issue that I haven't figured out yet is why the javaw process never ends. After shutting down an application started with Java Web Start, the javaw process is still running. If you start the same application 10 times there will be 10 javaw processes running after they have all been closed/exited.


