Java Web Start example

Source: Internet
Author: User

1. Create a New Java project named WebStart (the name may be retrieved randomly) and add the program:

Package JWS; </P> <p> Import javax. swing. *; </P> <p> public class helloworld {</P> <p> private jframe; </P> <p> private jpanel; </P> <p> private jlabel label; </P> <p> Public helloworld () {</P> <p> jframe = new jframe ("helloworld test frame"); </P> <p> label = new jlabel ("Hello, world! "); </P> <p> jpanel = new jpanel (); </P> <p> jpanel. add (Label); </P> <p> jframe. add (jpanel); </P> <p> jframe. pack (); </P> <p> jframe. setsize (400,150); </P> <p> jframe. setlocation (400,300); </P> <p> jframe. setvisible (true); </P> <p> jframe. setdefaclocloseoperation (jframe. exit_on_close ); </P> <p >}</P> <p> // main method executed during WebStart </P> <p> Public static void main (string ARGs []) {</P> <p> New helloworld (); </P> <p >}< br/>

 

2. Package the package into an executable jar package:

WebStart-> export-> runnable JAR file-> select the storage location and jar name (for example, D:/helloworld. Jar) and the class where the main method is running-> finish

 

3. Digital Signature:

Use the following command to sign the helloworld. jar package into an executable file:

 

A to DOS, go to the directory where the jar package of the application you want to publish is located, and run the following sentence:
Keytool-genkey-keystore mykeystore-alias same stest
(They will prompt you to enter the user name, password, and so on. Don't worry about them. Just enter them as prompted, but remember the password .. after running, they will create a file named mykeystore () in the current path ..)

 

B. Sign the jar package of the application to be released:
Jarsigner-keystore mykeystore yourtest. Jar named stest
(Yourtest. jar is your jar package name (helloworld here. jar), and you need to modify them .. you will be prompted to enter the password during the operation, that is, the password you set when generating the mykeystore file ..)

 

4. Create a WebStart folder under the webapps folder of Tomcat and inject the helloworld. jar file into it.

 

5. The following is a. JNLP file, which is a key file. The main file that Java Web Start can work on is also the key to loading server resources:

<? XML version = "1.0" encoding = "UTF-8"?> </P> <p> <! -- The codebase attribute indicates the top-level URL of the Application resource to be searched. The icon/jar elements below are all based on this URL. --> <br/> <JNLP codebase = "http: // localhost: 8080/WebStart/"> <br/> <information> <br/> <! -- <Br/> in the "Start"-"run" menu, enter "javaws" or "javaws-Viewer" to start Web Start, the WebStart application that has been installed on the client <br/> --> </P> <p> <! -- <Br/> title: Application title vendor: supplier; Title/vendor element is required, the application cache Viewer (Java application cache viewer) opened with the "javaws-Viewer" command is displayed) medium <br/> --> <br/> <title> helloworld </title> <br/> <vendor> lively Corporation </vendor> </P> <p> <description> helloworld test example for WebStart. </description> </P> <p> <! -- Homepage: stores the URLs of related documents of the application, such as the help file. It only serves the description function. --> <br/> <pomepage href = "http: // 127.0.0.1: 8080/WebStart/index.html "mce_href =" http: // 127.0.0.1: 8080/WebStart/index.html "/> </P> <p> <! -- <Br/> the icon specified by the icon is displayed in the application cache Viewer (as the Java Web application icon ), when you create a WebStart shortcut to the desktop in the viewer, it is displayed as a shortcut icon. Only GIF/JPEG formats are supported, other formats are invalid <br/> --> <br/> <icon href = "images/fish13.jpg" mce_href = "images/fish13.jpg"/> </P> <p> <! -- Splash mentioned in sun that it will appear in the pop-up screen when WebStart is started, but it may be due to speed problems, I have not observed --> <br/> <icon kind = "Splash" href = "images/fish13.jpg" mce_href = "images/fish13.jpg"/> </P> <p> <! -- Allow offline startup, you can use the javaws-Offline command --> <br/> <offline-allowed/> <br/> </Information> </P> <p> <resources> <br/> <! -- <Br/> specify the j2se version to be installed on the client. The value below is 1.5. You can also use 1.5 + to indicate a version later than 1.5. if the version is set to 1.5, while our machine is installed with 1.6 (so if I set it to 1.7 here, there will be a problem later), then the prompt is requesting JRE 1.5. After a while, the prompt is: the application cannot be enabled, prompt to manually update j2se version <br/> change to 1.5 + to run JRE of 1.6 <br/> --> <br/> <j2se version = "1.5 +" /> </P> <p> <! -- <Br/> specifies the JAR file to be downloaded to the local device (note that all files must be packaged before downloading). It can contain some resource files, such as icons/configuration files, you can use the getresource method to obtain <br/> --> <br/> <jar href = "helloworld. jar "mce_href =" helloworld. jar "/> <br/> </resources> </P> <p> <Security> <br/> <all-permissions/> <br/> </Security> </P> <p> <! -- Application-Desc is required. It specifies the class in the jar file executed during WebStart --> <br/> <application-Desc main-class = "JWS. helloworld "/> <br/> </JNLP>

Name the configuration file helloworld. JNLP and copy it to the Tomcat file where helloworld. jar is located.

 

6. Enable the Tomcat server and Use http: // localhost: 8080/WebStart/helloworld. JNLP can access helloworld. JNLP file, the server then according to helloworld. JNLP file to load helloworld. JAR file, you can directly run the server resources on the client. It downloads the server resources to the client before running, each access will go to the server to check whether the executable jar package is the latest. If it is not the latest, reload the latest package and run it again to keep the latest version of the resource ;. When no changes are made, the program will be started directly from the client, which will be faster.

 

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.