JNLP (Java Web Start) (GO)

Source: Internet
Author: User

JNLP (Java Network launching Protocol) is a Java-provided way to execute Java applications directly through a browser, allowing you to open a Java application directly from a URL connection on a Web page. Java desktop applications are published in a JNLP manner, and if the version is upgraded, it is not necessary to release the version to all users, only the version of the server needs to be updated, which is equivalent to the advantages of having a Java application with a Web application.

JNLP File Specific description edit <?xml version= "1.0" encoding= "UTF-8"?><!--codebase property indicates the top-level URL of the Search application resource, the following Icon/jar element is based on this URL as basic .--> &LT;JNLP codebase= "Http://127.0.0.1:8081/webstart" ><information><!--enter "Javaws" or "javaws" in the "Start"-"Run" menu -viewer "Start Web Start, you will see that the client has installed the Webstart application--><!--title: Application Title Vendor: The vendor Title/vendor element must be displayed in the" Javaws- Viewer command opens in the Application Cache Viewer (Java application cache Viewer)--><title>helloworld</title><vendor> Lively Corporation</vendor><description>helloworld Test Example for webstart.</description><!- -homepage: A URL that holds relevant documents about the application, such as Help files, is just a description action-->JNLP Deployment App Edit (1) Write the relevant application, packaged into a series of Jars, (2) modify the corresponding JNLP content according to the JNLP file description, modify the corresponding URL and jar, (3) Deploy the JNLP file and jar to the appropriate Web container, and (4) write the access page to use the application ( Also download the JNLP file to run the application using JWS);Supplemental edits If the jar requires access to a local file resource, you need to sign your jar file. Generate a KeyStore file with Keytool at the command line: Keytool-genkey-keystore you.keystore–alias youapp command line with Jarsigner signature, Of course this time you need to generate KeyStore password: Jarsigner-keystore you.keystore apptest.jar Youapp redeploy.

Http://baike.baidu.com/link?url=wt-uXbvZdkzVSZRDXEBEAo5ZcFuOmleD2DnNrZ2aIcC08_3RS3YCAuzR6AwDuLu6wlVYa9pBixDSysT0RIw5hq

1.Java Web Start Introduction
Java Web Start is a new technology that helps client-side application development, which is unique in that it frees you to care about how a client is launched (from a Web browser or desktop). Also, the technology provides a collection deployment scenario that enables the Web server to publish and update client code independently.
Java Web Start is a software technology that contains the portability of applets, the maintainability of Servlets and Java Server Pages (JSP), and the simplicity of markup languages such as XML and HTML. It is a Java-based application that allows you to launch, deploy, and update functionality from a standard Web server to 2 client applications.
Java Web start itself is a Java application, so the software is platform independent, and any client system that supports the JAVA2 platform supports the software. When the client application starts, Java Web start automatically performs the update, downloading the version of the crime from the Web while loading the application from the original cache. Java Web Start also provides a Java application Manager (Java Application Manager) utility that provides a variety of options, such as clearing the cache of downloaded applications, specifying the use of multiple JRE, setting up an HTTP proxy, It also allows end users to organize their Java applications.
Java Web Start site:
http://java.sun.com/javase/technologies/desktop/javawebstart/index.jsp
JNPL Specification: http://jcp.org/en/jsr/detail?id=056

2.JNLP Introduction
The JNLP (full name of Java Network Launch Protocol) means the Java Networking load protocol. JNLP is an XML file that provides basic elements and descriptions for the Java Web start application. JNLP is the core of Java Web start.
The JNLP application enables the application to be accessed through a Web browser like a standard Java applet, and the JNLP can be restricted to a secure "sandbox" on the client host. Unlike the APPLETS,JNLP application that does not run inside the browser of the customer Instead, a Web browser serves only as a starting point or installation tool for an application.
Java desktop applications are published in a JNLP manner, and if the version is upgraded, it is not necessary to release the version to all users, only the version of the server needs to be updated, which is equivalent to the advantages of having a Java application with a Web application.

3. Example Application
1. Build a Web server
A) Tomcat runs normally.
b) Locate the Web. xml file under tomcathome/conf and add application/x-java-jnlp-file to support the JNLP file, as shown in:


2. Deploy the Application
A) Develop the application program.
b) Make the application and resource files into one or more jar packages.
c) If the application uses local resources to run the application, then your application must be signed before it can be published, and if you do not need to use local resources, you can publish the application in this step.
d) How to sign the application:
I. First make sure that you have installed the J2SE environment safely, and that you have the Keytool tool, which is located in the bin directory of the J2SE SDK, as shown in:


II. To DOS, enter the directory where you need to publish the application's jar, run the following sentence Keytool–genkey–keystore Mykeystore–alias jwstest It will prompt you to enter the user name, password, etc., ignore it, Follow the prompts to enter them, but be sure to remember the password. Run end it will create a file named Mykeystore under the current path. As shown in the following:

III. If you want to check the contents of the Mykeystore file that you just generated, you can enter this Keytool–list-keystore mykeystore, and then enter the password:
The display results are as follows:


Iv. sign the jar package for which you need to publish the application, and run this sentence: Jarsigner–keystore mykeystore yourtest.jar jwstest, Where Yourtest.jar is the name of your jar package, you need to modify it, and nothing else needs to be changed. The runtime prompts you for a password, which is the password you set when you just generated the Mykeystore file. As shown in the following:


e) Deploy the application and copy the signed jar package into the Web project directory (note: cannot be copied to the Web-inf directory).

3.JNLP File Introduction
A) write the core configuration file for Java Web start JNLP. The JNLP file conforms to the standard XML syntax, which means that JNLP is an XML file. The best way to write is to modify an existing JNLP file.

<?xml version= "1.0" encoding= "UTF-8"?> <!--JNLP Spec must be 1.0 or higher, the number of times is 1.0+; The CODEBASE attribute indicates the top-level URL of the search application resource. The href attribute is set to allow the application to be incorporated into the Java Web Start Application Manager--&LT;JNLP spec= "1.0+" codebase= "Http://localhost:8081/NetJavaProject" href= "JWSPALETTE.JNLP" > <!--information tags (such as title, vendor, etc.) are used to provide additional information about the application from the Java Web Start application Manager. The homepage ref property is a Web page that is specifically used to point to the web URL so that the user can go to provide more information about the application. The most interesting information tag is the Offline-allowed property, which determines whether the client Java application can be started offline. When a client Java application is run offline, Java Web Start will continue to determine the most recent file from the Web server, and in most cases this scenario will cause a fast timeout (because the location is specified to start offline) and the application is booted from the local cache--&LT ;information> <!--title: Application title Vendor: Vendor; Title/vendor element must be displayed in the application cache viewer that is opened in the "Javaws-viewer" command (Java Application cache Viewer)--<title>netjava application </title> <vendor>netjava& Lt;/vendor> <!-description: Description of the application, can have many pairs <description> </description>, optional---<descrip Tion>netjava Application </description> <!--offline-allowed: Select to allow offline startup, you can use the Javaws–offine command-<offline-allowed/> </information> <!--the resource tag takes into account the JNLP file specifying which jar files The application uses and how to download the jar files; that is, eager or leisurely. This feature is very helpful when the user is downloading a large number of files and not all of the files are required for the client to execute. By default, most resources are eagerly downloaded, in which case the JAR files and resources are downloaded before the application is started. A leisurely download of resources is only downloaded if the Java virtual machine (JVM) triggers a resource or file to be loaded from the application. An example of a leisurely download resource is the client's help file, which is downloaded only when the user actually requests a help file from the client, given the faster startup and execution of the client. However, once a user requests a Help file, the appropriate JAR is downloaded during the request and accompanied by a window that informs the user about the approximate download time-<resources> <!-Specifies the version of the J2SE that the client needs to install, specified below as 1 .6+, if the version is 1.4, when you connect this JNLP file, you are prompted to update the J2SE version--<j2se version= "1.6+"/> <!-Specify the jar file to download to the local (note: All files need to be packaged to download) , you can include some resource files, such as icons/configuration files, but you must use the class's GetResource () method to get the <jar href= "Palette.jar"/> &lt      ;/resources> <!--specified operating system and JDK version-<resources os= "Windows" > <j2se version= "1.6+"/> </resources> <!-application-desc must specify which class in the jar file to execute when Web start starts and <application-desC main-class= "Cn.netjava.palette.Palette"/> <!--security properties. By default, any Java application launched from the Java Web start client is executed in a secure, restricted environment that does not allow local file access, network connectivity to other computers, and so on. However, for a rich client with full access to the client and the network, the All-permissions value is used to give the client full access. For full access to the local machine, all JAR files and resources used and loaded by the Java application must be digitally signed-<security> <all-permissions/> </   Security> </jnlp>

4.JSP page  
Write the following page for access: (index.jsp)  

<%@ page language= "java" contenttype= "text/html;      Charset=utf-8 "pageencoding=" UTF-8 "%> <% String Path = Request.getcontextpath ();              String basepath = request.getscheme () + "://" + request.getservername () + ":" + request.getserverport ()      + path + "/";  System.out.println (BasePath); %> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" > 

  




5. Complete the release and testing
First, the Web packages the project into a war package, and then copies the war package to the WebApps directory in the Tomcat directory
, and start Tomcat. The access path for the test is http://localhost:8080/NetJavaProject/index.jsp. This will enable us to post the Swing application project on the Internet. Of course, there are a lot of details, I look forward to you to revise the details well ...

JNLP Reference:
Http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/contents.html
Http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html

http://convolute.iteye.com/blog/564904

How to open JNLP file:
First make sure you've installed the JRE.
Changed the environment variables
Then, start--run--cmd
Javaws D:\XXXX\XXXX\XXXX.JNLP
If your JRE is not a problem, you should have a Java program on your screen and start downloading it.

JNLP (Java Web Start) (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.