Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Network Launch Protocol (JNLP) Tomas Bober. What it is A clever way to manage the contents of your java applications on a client’s computer. If you.

Similar presentations


Presentation on theme: "Java Network Launch Protocol (JNLP) Tomas Bober. What it is A clever way to manage the contents of your java applications on a client’s computer. If you."— Presentation transcript:

1 Java Network Launch Protocol (JNLP) Tomas Bober

2 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.

3 How it works First time users of your application access the JNLP Server through the provided URL They allow a JRE plug-in to be installed on their system. This installs the client on the user’s machine. Anytime the resource files are updated on the web server, the update is passed down to the clients Users don’t worry about having the latest files since update are done automatically.

4 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.

5 Pictorial Representation

6 How it works The JNLP file is actually an XML file It uses the XML format to direct the JNLP Client to retrieve resouce files, set security permissions, and how to handle the splash screen. The JNLP client executes the commands on the user’s machine and sets up the enviornment for the JVM. Very similar to batch files on a windows system. JNLP files can be layered… one main and several child layers can be used to obtain jar another other resources.

7 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.

8 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.

9 Disadvantages Users need to accept the client install Client needs to run before the application can run Users see a splash screen before the application starts

10 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

11 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

12 Write the basic app Compile and execute the following code locally on your computer through the command prompt import java.awt.*; import javax.swing.*; import java.io.*; import java.net.*; public class TheTime { public static void main(String args[]) { JFrame frame = new JFrame("Time Check"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel();

13 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);

14 Code Part 3 } finally { if (reader != null) { try { reader.close(); } catch (IOException ignored) { } label.setText(message); frame.pack(); frame.show(); }

15 Writing the.jnlp Now that you know the code works, we will make it work with JNLP. Open a text editor and copy and paste the following code into it. Save it as a time.jnlp

16 .jnlp Code Part 1 <jnlp spec="1.0+" codebase="file:///c:/JNLP" > Time Check NJIT - CS633 JNLP Demo

17 .jnlp Code Part 2 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

18 The.jnlp file Security tags are not always required, but here we set the security permissions to that of the j2ee environment on the client side. The resources section is where you describe what your application needs to run –We need to specify the j2se environment since that is what will be used to run this application –We also specify the.jar file that contains the application

19 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.

20 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

21 Running the app locally To execute, just double click on time.jnlp You will see a screen like this. Click Run on the Security warning about the signed JAR file You will see the same output as before.

22 Running the app locally The time is going to be different in this output though. Here, the JNLP launcher opens the codebase directory, grabs whatever JAR file is specified in the resources, and executes it using the j2se environment specified. To update he app, we would just need to change the JAR file. Accessing the app would be exactly the same. The.jnlp file would automatically grab the updated JAR file and resources. It would then run using those rather then the old version.

23 Running the app on AFS First you need to ensure that Apache Tomcat is working correctly. In a browser type http://afs35.njit.edu/~userid It can be afs31–35 since they’re allowed to run the apache web server. You should see your home page You can double check Apache by going to the page listed in the professor’s lecture notes.

24 Add a new MIME type Apache needs to know how to handle files of type.jnlp, but this feature is currently not setup in AFS. The normal way of resolving this is to add a new MIME type by opening the Apache Group\Apache\conf\mime.types file and inserting application/x-java-jnlp-file JNLP into the declarations. However, we as students, don’t have access to this file

25 MIME workaround To get around this limitation, create a file called.htaccess in your public_html directory. Paste AddType application/x-java-jnlp-file.jnlp into the file This is another way to tell Apache how to handle the.jnlp files types without having access to the configuration files.

26 Changing the.jnlp You need to change the codebase in the.jnlp file to the location of the JAR files after you paste it to a AFS server. I changed mine to codebase="http://afs33.njit.edu/~trb2/JNLP" You need to specify the server you will be using. Meaning you need to write afs33.njit.edu rather then web.njit.edu

27 Running the.jnlp from AFS Copy and paste all the files to your public_html folder. I chose to put mine in a JNLP directory. To execute the program go to http://web.njit.edu/~yourid/JNLP/time.jnlp You will notice a new screen that looks like the following:

28 New screen This screen launches the program on your local machine. If you check the box, you will not see this screen anymore and the.jnlp will launch automatically.

29 Automatic Updating If you check the “trust content from this publisher” on the singed JAR file screen, you won’t get the warning anymore You will notice that the.jnlp file is automatically updated. You can verify this by looking at the download folder using firefox. This updated file automatically grabs updated resources and executes the program.

30 Local Problems / Solutions If your program compiles and runs but does not execute using JNLP try one of the following: –Make sure you specify the code base properly. Windows uses “ C:\JNLP ” while JNLP uses different slashes “ file:///c:/JNLP ” –Make sure you spelled the name of the.jar file correctly –Make sure you spelled the main-class correctly

31 Remote Problems-Solutions You only see the contents of the.jnlp file rather then it executing –Apache doesn’t know how to handle the.jnlp file. Make sure you specified the new MIME type correctly. –The.htaccess file needs to have the period in front of the “htaccess”

32 Remote Problems-Solutions The.jnlp file executes, but the application fails to launch –Make sure apache is working, if not, log ito the SSH client and run “ tomcat.setup ” then wait a day. –After installation, make sure you access your code from afs31-afs33 when you run Tomcat. –Make sure you spelled the names and location of all resources correctly.

33 Resources http://java.sun.com/docs/books/tutorial/deployment/w ebstart/deploying.htmlhttp://java.sun.com/docs/books/tutorial/deployment/w ebstart/deploying.html http://www.informit.com/articles/article.aspx?p=25043 &rl=1http://www.informit.com/articles/article.aspx?p=25043 &rl=1 http://www.informit.com/articles/article.aspx?p=25044 &rl=1http://www.informit.com/articles/article.aspx?p=25044 &rl=1 http://www.javascriptkit.com/howto/htaccess.shtml http://www.ufaq.org/navcom/mime_tutorial.html


Download ppt "Java Network Launch Protocol (JNLP) Tomas Bober. What it is A clever way to manage the contents of your java applications on a client’s computer. If you."

Similar presentations


Ads by Google