Spec-Zone .ru
спецификации, руководства, описания, API
Trail: Deployment
Lesson: Java Applets
Section: Getting Started With Applets
Deploying an Applet
Home Page > Deployment > Java Applets

Deploying an Applet

To deploy your Java applet, first compile the source code and package it as a JAR file.

Java applets can be launched in two ways.

The Deployment Toolkit script contains useful JavaScript functions that can be used to deploy applets in a web page.

If you are unfamiliar with these deployment technologies, review the Deployment In-Depth lesson before proceeding further.

Here are some step-by-step instructions to package and deploy your applet. The Dynamic Tree Demo applet is used to illustrate applet deployment. You might want to set up build scripts to execute some of the following steps.


Note:  

If you don't see the applet running, make sure that you have at least the Java 2 Platform, Standard Edition (J2SE) 1.4.2 release on your client. If not, download and install the latest release of the Java SE Development Kit (JDK).



Note:  

If you don't see the example running, you might need to enable the JavaScript interpreter in your browser so that the Deployment Toolkit script can function properly.


  1. Compile your applet's Java code and make sure all class files and resources such as images are in a separate directory.

    In the case of the DynamicTree Demo applet, the compiled classes are placed in the build/classes/appletComponentArch directory.

  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/classes/appletComponentArch directory.

    % cd build/classes
    % jar cvf DynamicTreeDemo.jar appletComponentArch
    
    See the Packaging Programs in JAR Files lesson to learn more about creating and using JAR files.
  3. Create a JNLP file that describes how your applet should be launched.

    Here is the JNLP file used to launch the Dynamic Tree Demo applet.

    The source for dynamictree-applet.jnlp follows:
        
    <?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" />
            <jar href="DynamicTreeDemo.jar" main="true" />
    
        </resources>
        <applet-desc 
             name="Dynamic Tree Demo Applet"
             main-class="components.DynamicTreeApplet"
             width="300"
             height="300">
         </applet-desc>
         <update check="background"/>
    </jnlp>                                   
    
    The topic, Structure of the JNLP File, describes JNLP file syntax and options.
  4. Create the HTML page that will display the applet. Invoke Deployment Toolkit functions to deploy the applet.

    In our example, the Dynamic Tree Demo applet is deployed in AppletPage.html.

    <body>
        <!-- ... -->
        <script src="http://www.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>
    
  5. Place the applet's JAR file, JNLP file and HTML page in the appropriate folder(s).

    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.

  6. Open the applet's HTML page in a browser to view the applet. Check the Java Console log for error and debugging messages.

Download source code for the Dynamic Tree Demo Applet example to experiment further.


Problems with the examples? Try Compiling and Running the Examples: FAQs.
Complaints? Compliments? Suggestions? Give us your feedback.

Previous page: Developing an Applet
Next page: Deploying With the Applet Tag