April 24, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Where to Start with Java Web Start, Page 3

  • July 8, 2009
  • By Sridhar M S, Sridhar M S
  • Send Email »
  • More Articles »

Launching an Application Using Java Web Start

As discussed previously, you need a web page to launch an application with Java Web Start. As an example, take the following code snippet for a HTML file named MyApp.html, which contains a link to launch the application pointing to MyApp.jnlp:
<html>
  <head> 
      <title>JNLP usage demo!</title>
  </head>
  <body> 
       <a href="MyApp.jnlp">Launch My Application</a>
  </body>
</html>

When you invoke the file MyApp.html from a browser with a URL that points to the file (maybe something like http://localhost:8080/MyApp.html), a web page will display the link for "Launch My Application." On clicking this link (as long as the .jnlp MIME type is configured), Java Web Start launches the application MyApp with the parameters provided in the demo JNLP file.

When Java Web Start Is Not Available on User's System

During development, you usually have Java Web Start installed on most of your systems, but this may not always be the case during deployment. Many times, end-user systems will not have Java Web Start installed and hence the clients will not behave as you expect. The user will just assume that your application does not work.

In such cases, you need your application launcher to be at least intelligent enough to tell the user why the application failed to launch. Providing this intelligence requires JavaScript (see below). You must run this script in the MyApp.html as part of the onLoad method. Based on the return type, a corrective action such as displaying a message about the non-availability of Java Web Start will be necessary.
<SCRIPT LANGUAGE="JavaScript"> 
var javawsInstalled = 0; 
isIE = "false"; 
if (navigator.mimeTypes && navigator.mimeTypes.length) { 
   jnlpTrue = navigator.mimeTypes['application/x-java-jnlp-file']; 
   if (jnlpTrue) { 
      javawsInstalled = 1; 
   } 
} 
else { 
   isIE = "true"; 
} 
</SCRIPT>

The above JavaScript verifies whether Java is installed when the browser is Netscape. You can expand the script to cover Internet Explorer as well.

This article has given you enough information to get started with Java Web Start. When you have mastered the basics, you can accomplish much more with the technology by customizing the .jnlp file and exploring more of its concepts.

For Further Reading

  • " Java Web Start to the Rescue" (from Sun Developer Network)

    About the Author

    Sridhar M S is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.





  • Page 3 of 3



    Comment and Contribute

     


    (Maximum characters: 1200). You have characters left.

     

     


    Sitemap | Contact Us

    Rocket Fuel