Skip navigation.

Mr Green's Coffeshop

Heal the world, smoke weed!

Java Web Start

,

Java Web Start allows you to launch a Java application by clicking on a web page link. The application is cached locally and every time the application runs, Java Web Start checks if there is a newer version on the server, and if so the new version is downloaded.

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.

Signing JAR files.File permissions

Comments

Anonymous 6. April 2006, 20:37

Rich writes:

Great instructions on signing the jar file for webstart, very useful, thanks.

Anonymous 27. November 2006, 10:01

Anonymous writes:

an answer to why javaw process(es) keep running...

did you code to return system resources upon close operation?
such as through inserting

'this.setDefaultCloseOperation (this.EXIT_ON_CLOSE);

assuming 'this' is the JFrame...


hope that helped...

Anonymous 12. April 2007, 16:49

Anonymous writes:

I am also having problems with returning resources. I am using 'this.setDefaultCloseOperation (this.EXIT_ON_CLOSE); This only occurs when I run my app from webstart, if I run it from the desktop it returns normally.

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies

December 2009
M T W T F S S
November 2009January 2010
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31