We often get asked if applications built with Esri’s ArcGIS APIs can be used with Java(tm) Web Start. The answer is ‘yes’, but people still experience a “trial and error” process, unfortunately. In a sincere effort to try and clarify how to use Java Web Start to deliver your ArcGIS Runtime Java apps, here is a simple deployment scenario that we hope you will find informative.
About Java Web Start
Java Web Start is an application deployment technology that is widely used throughout the Java development landscape. Rich, standalone Java applications can be deployed with a single click over the network using Java Web Start Technology. Java Web Start ensures the most current version of the application will be deployed, as well as the correct version of the Java Runtime Environment (JRE). For more detailed information about how it works and the Java Network Launching Protocol (JNLP) specification, go to http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136112.html
A Simple Example
I developed a simple ArcGIS Runtime Java application that is to always be connected. In other words, it will not use a “local” runtime and will never be disconnected from the internet in any way. Therefore, all of the business logic for the application will be running in Java, accessing a Web Map from ArcGIS Online, and the application is made up solely of a handful of jar files.
I found a machine to act as my target for delivering my app to and installed the Java SE Runtime Environment v7.x.
For my development environment, I started out with the code in Netbeans 7.2. I configured my project to use Web Start as the start-up mechanism by simply right-clicking on the project and selecting “Set Configuration–>Web Start”. By the way, Netbeans is not a requirement for using Java Web Start. I chose this approach because of Netbeans’ built-in tooling for setting up your Java Web Start environment automatically. In other words, I’m lazy! .
Now, I was able to run my application from within Netbeans, which performed the needed tasks for making a Java Web Start deployment:
- generated my JNLP file
- compiled my code into an executable jar
- signed the jar and all dependent jars
- copied everything into a single location for distribution.
The jar called “WebStartTest.jar” contains all of my application logic. The “lib” folder contains all of the application-dependent jars, including the ArcGIS Runtime jars. All of the jars are digitally signed, a requirement for Java Web Start to securely execute Java classes on the target machine.
The “launch.jnlp” file is what launches the Java app from a Web URI, for example, “http://mywebserver/weatherapp/launch.jnlp”. It tells the Web Server to grab the specified app jars and stream them to the client machine so they run locally. The JNLP file is simply an XML file, used to provide the Web Server and the target machine’s Java Runtime Environment with the instructions on how to deliver the app to the target and execute the app. I recommend spending a little time reviewing the JNLP specification for an explanation of the tags.
The “launch.html” file is used as a launch site, which redirects to the launch.jnlp file.
After I verified that my application ran properly from within Netbeans using Java Web Start, I copied the generated “launch” JNLP, jars, and the “launch” html file from my Netbeans project “dist” folder into a folder on my Web Server. I named the folder “weatherapp”, the name of my application.
At this point, I should have been ready to launch my app by accessing the launch.html file over HTTP. However, there was one more vital step to take. I needed to edit the JNLP file (now located on the Web Server) to insert the “codebase” attribute into the <jnlp> tag, telling Java Web Start where to find the jars on the Web Server to be delivered:
<jnlp codebase="http://mywebserver/weatherapp/" href="launch.jnlp" spec="1.0+" >
That was it for the setup. In a Web browser of my choice I navigated to http://mywebserver/weatherapp/launch.html.
Clicking on the launch button on this page allowed the app to stream to the client machine and execute.
Your Java applications developed with the ArcGIS Runtime SDK for Java can easily be delivered to your users via Java Web Start Technology. Netbeans is a nice platform to use for jump-starting a Web Start deployment. It is capable of handling the jar-signing and JNLP file creation tasks.