Deploying An Applet In Under 10 Minutes

JavaTM SE 6u10 allows us to deploy applets using Java Network Launch Protocol (JNLP). In fact, this is now a recommended best practice!

Tired of dealing with pesky browser issues when deploying applets? Think Deployment Toolkit.          
We now have the Deployment Toolkit, a JavaScript library with nifty functions to deploy applets and Java Web Start applications. It takes care of all underlying browser idiosyncracies :-)

Check it out at http://java.com/js/deployJava.js or https://www.java.com/js/deployJava.js

Let's walk through some steps to understand applet deployment. Check the "Related Reading" section to see more documentation on relevant technologies. We'll use the "Dynamic Tree Demo" applet as an example. You may want to setup build scripts to execute some of the following steps.

  1. Compile / build your applet's Java code and make sure all class files and resources such as images etc. are in a separate directory, example build/components.
  2. Create a jar file containing your applet's class files and resources. For example, the following command creates a jar file with the class files in the build/components directory.
    cd build 
    jar cvf  DynamicTreeDemo.jar  components
    			  		
  3. Sign your jar file if the applet needs special security permissions, for example, to read or write a file on client etc.
    jarsigner -keystore myKeyStore -storepass abc123 -keypass abc123 DynamicTreeDemo.jar johndoe
    where
    • keystore is setup and located at "myKeyStore"
    • alias is "johndoe"
    • keystore password and alias password are "abc123"
  4. Create a JNLP file that describes how your applet should be launched.
    dynamictree-applet.jnlp
    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp spec="1.0+" codebase="" href="">
        <information>
            <title>Dynamic Tree Demo</title>
    
            <vendor>Dynamic Team</vendor>
        </information>
        <resources>
            <!-- Application Resources -->
            <j2se version="1.6+"
                  href="http://java.sun.com/products/autodl/j2se"
                  max-heap-size="128m" />
    
            <jar href="DynamicTreeDemo.jar" main="true" />
    
        </resources>
        <applet-desc 
             name="Dynamic Tree Demo Applet"
             main-class="components.DynamicTreeApplet"
             width="300"
             height="300">
         </applet-desc>
    </jnlp>					
  5. Create the HTML page that will display the applet. Invoke the runApplet function from the Deployment Toolkit to deploy the applet.
    AppletPage.html
    <body>
        ....
        <script src="http://java.com/js/deployJava.js"></script>
    
        <script> 
            var attributes = { code:'components.DynamicTreeApplet',  width:300, height:300} ; 
            var parameters = {jnlp_href: 'dynamictree-applet.jnlp'} ; 
            deployJava.runApplet(attributes, parameters, '1.6'); 
        </script>
        ....
    </body>					
  6. For this example, place DynamicTreeDemo.jar, dynamictree-applet.jnlp, and AppletPage.html in the same directory on the local machine or a web server. A web server is not required for testing this applet.
  7. View AppletPage.html in a web browser. The Dynamic Tree Demo Applet will be displayed. View Java Console Log for error and debug messages.

This method of applet deployment should work on JDK 7 too, once the required features are forward ported from Java SE 6u10.

Want to learn more about the Deployment Toolkit? Check out Deployment Toolkit 101.

Source Code

You can download the NetBeans project for this example


Related Reading


We'd love to hear feedback! Tell us about other deployment related topics that you'd like information on.

Stay tuned for more blogs on this subject...

-- Sowmya Kannan

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Blog about Java technology documentation and news about Java releases.

Search

Categories
Archives
« July 2015
SunMonTueWedThuFriSat
   
2
3
4
5
6
7
8
9
10
11
12
13
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
       
Today