The Java Tutorials' Weblog
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.
- 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.
-
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
-
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"
-
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> -
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> - 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.
- 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
- Java Network Launch Protocol (JNLP)
- JNLP File Syntax
- Editing a JNLP file in Netbeans IDE (although this tutorial is written in the context of Java Web Start applications, most of the information is still relevant)
- JNLP Support in the New Java Plug-in
- Next Generation Java Plug-in aka New Java Plug-in
- Release Notes for the Next-Generation Java™ Plug-In Technology JDK 6u10
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
Posted at 10:11PM Mar 31, 2009 by The Java Tutorial Team | Comments[16]
Tuesday Mar 31, 2009
Good. I want to know such kind of information. Post more. JDK has so many useful information and seldom people know about it.
Posted by Lawrence on April 07, 2009 at 06:59 PM PDT #
As soon as Update 10 was out, I tried it for Sweet Home 3D applet version at
http://www.sweethome3d.eu/SweetHome3DOnLine.html with its JNLP file http://www.sweethome3d.eu/SweetHome3DApplet.jnlp .
It worked very well even for Linux and Mac OS X (with a JVM 1.5).
Posted by Emmanuel Puybaret on April 07, 2009 at 09:42 PM PDT #
java 1.6 Update 10 13 are just good moves.
I also use it.
Here : http://www.free-visit.com/index.php?option=com_content&task=view&id=37&Itemid=85
Posted by Thierry Milard on April 08, 2009 at 02:01 AM PDT #
I would like to know if the JSObject is available through this method.
When I used the JNLP I saw that this is not possible that's why I used the classic applet.
Should I suppose that with this way the JSObject again is not available?
s there any way around this ?
Cheers
Posted by PostMan on April 08, 2009 at 07:36 AM PDT #
I am glad you mention JSObject. I will be posting another blog about interactions between Java applets and JavaScript (via JSObject). Stay tuned...
Posted by Sowmya Kannan on April 08, 2009 at 08:21 AM PDT #
BTW, the Live Connect Spec and implementation is much improved now. Here is a link to related 6u10 documentation
http://java.sun.com/javase/6/webnotes/6u10/plugin2/liveconnect/index.html
I'll post a few usage examples in the next few days.
Posted by Sowmya Kannan on April 08, 2009 at 08:25 AM PDT #
I would be interested to know if this code works across all browser flavors.
Posted by anand on April 08, 2009 at 11:04 PM PDT #
Ruth, Our web folks suggest trying the following -
http://java.com/en/download/installed.jsp - This tells the user whether they have the old / latest version. If they have the latest version, I would go to
http://java.com/en/download/help/testvm.xml - This tells the user if their latest version is working or not.
If not, I would troubleshoot from the pogo end and see what they have setup
Posted by Sowmya Kannan on April 13, 2009 at 10:31 AM PDT #
Should this work even if my applet is in a package and this applet uses classes from another package? I put both packages in one jar, but it didn't work for me, it can't find the applet class.
Any suggestions?
Posted by Alexandra N on May 06, 2009 at 08:23 AM PDT #
Check out the new Deployment Tutorial on java.sun.com. Includes in-depth lessons on the development and deployment of applets and Java Web Start applications.
http://java.sun.com/docs/books/tutorial/deployment/index.html
Posted by Sowmya Kannan on September 24, 2009 at 11:36 AM PDT #
I think we followed all the good advice, and we found a flaw in Sun's deployment process. To see it, one must un-install Java.
At the stage of downloading Java, triggered by deployJava.js, the user is prompted to save a file to disk, not to execute the file. Depending on browser settings, the user might even fail to locate and execute the file.
This is due to the following technical details:
http://dl8-cdn-03.sun.com/s/ESD6/JSCDL/jdk/6u16-b01/jre-6u16-windows-i586-iftw-k.exe?e=1252122644805&h=9b3c9315f48243ef2d2af5c57300fe28/&filename=jre-6u16-windows-i586-iftw-k.exe
httpfox helps us get the response headers of this download:
(Status-Line) HTTP/1.1 200 OK
Server Apache
Accept-Ranges bytes
Content-Length 236832
Content-Disposition attachment
Content-Type application/download
Age 74451
Date Sat, 05 Sep 2009 04:11:08 GMT
Last-Modified Sat, 01 Aug 2009 00:29:08 GMT
Connection close
"Content-Disposition attachment"
appears to be an unsuitable setting for this type of installation, quite unfortunate considering all the efforts that obviously were spent on that process.
We would like to be kept informed about progess in developing the installation process.
Posted by Bernard on October 13, 2009 at 08:00 PM PDT #
Correction: "Content-Type application/download" not
"Content-Disposition attachment" is more likely the reason for the unfortunate behavior.
The user gets the message: "You have chosen to open
jre-6u16-windows-i586-iftw-k.exe
which is a: Binary File
from http://dl8-cdn-03.sun.com
Would you like to save this file?
[Save File] [Cancel]
There is no option to execute it.
Posted by Bernard on October 13, 2009 at 08:51 PM PDT #
I think JOption Pane is the part of this.
Posted by Degree Online on October 26, 2009 at 12:59 PM PDT #
How can i use this code ? Any Logic ?
href="http://java.sun.com/products/autodl/j2se"
max-heap-size="128m" />
Posted by modern furniture on November 02, 2009 at 01:19 PM PST #
WONDERFUL!
Posted by buy aion card on November 05, 2009 at 09:16 PM PST #
GOOD POST!
Posted by cheap wow gold on November 05, 2009 at 09:17 PM PST #