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.
In the
case of the DynamicTree Demo applet, the compiled classes are placed in the
build/classes/appletComponentArch
directory.
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
Here is the JNLP file used to launch the Dynamic Tree Demo applet.
The source fordynamictree-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>
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>
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.
Download source code for the Dynamic Tree Demo Applet example to experiment further.