Download Java Network Launch Protocol (JNLP) - Managing Java Applications Resources and more Slides Java Programming in PDF only on Docsity!
Java Network Launch Protocol (JNLP)
What it is
• A clever way to manage the contents of your java applications
on a client’s computer.
• If you have an complicated application requiring resources to
be downloaded to a client’s machine, this technology
manages those resources.
• This technology ensures all users of your java applications
always have the most up to date files to work from.
• This is done with almost no effort on the user’s end.
More Details
- When a regular application is launched, the location of resources
must already be known
- This is tough to do with a distributed application since a developer
would need to specify all file paths on a user’s computer as well as
web resources.
- But there is a better way: A launcher Program
- This “launcher” program collects local and web resources needed by
the application and lets the JVM know where everything is.
- This way, when the application starts, all the resources are already
available.
Pictorial Representation
Client Computer JNLP Client URL JNLP Server With resource files Web Resources JVM Resources Java Application Native Rsources
Advantages
• A rich client environment at runtime. Developers can use a new
API to access system resources.
• A secure deployment solution. End users can trust a reliable
JNLP Client and let that client manage additional files required
by the application.
• Applications can evolve through incremental updates.
• Multiple JREs management and automatic installation of
additional JREs and optional packages.
More Advantages
• Offline operation. Deployed applications can work even
without a connection with the deployment server.
• Automatic installation of native code/libraries. Some Java
programs may need some platform-specific support for
running.
• JNLP Client management console.
• The capability of using platform-dependent facilities such as
shortcuts, accelerators, and utilities.
An Example
• In this example we will setup the environment
for using .jnlp files
• Go through the creation of the files needed to
execute program with JNLP.
• Deploy the application locally
• Deploy the application on NJITs AFS server
running Apache Tomcat
The Application
• This example connects to United States National Institute of
Standards and Technology and retrieves the current time
• It is a JFrame, not an applet, since it doesn’t extend applet and
therefore can be compiled and executed from the command line
• Is not embedded in an html file
Code Part 2
Container content = frame.getContentPane(); content.add(label, BorderLayout.CENTER); String message = "missing"; BufferedReader reader = null; try { Socket socket = new Socket("time.nist.gov", 13); InputStream is = socket.getInputStream(); InputStreamReader isr = new InputStreamReader(is); reader = new BufferedReader(isr); reader.readLine(); // skip blank line message = reader.readLine(); } catch (MalformedURLException e) { System.err.println("Malformed: " + e); } catch (IOException e) { System.err.println("I/O Exception: " + e);
Code Part 3
} finally { if (reader != null) { try { reader.close(); } catch (IOException ignored) { } } } label.setText(message); frame.pack(); frame.show(); } }
.jnlp Code Part 1
Time Check NJIT - CS633 JNLP Demo .jnlp Code Part 2
<application-desc main-class="TheTime" /> • The Codebase is the location of the .jar file we will create for
this application
• The Information section contains the information the splash
screen will display
More on the .jnlp file
• We specify the main class as TheTime in the
Application tag. This is the name of our
compiled class. We would not need to do this
if we specified one class in the jar file as the
main class. This would be done if we used
multiple jar files.
Create the JAR file
• First create the JAR file
jar cf JNLPTime.jar TheTime.class
• Create a key in the keystore
keytool -genkey -keystore myKeys -alias jdc
• Sign the JAR file
jarsigner -keystore myKeys JNLPTime.jar jdc