All rights reserved: (Xiaodaoxiaodao) Blue knife xiaodaoxiaodao@gmail.com
Http://www.blogjava.net/xiaodaoxiaodao/articles/103469.html
Reprint please indicate source/author
JNLP specification about Web start can be downloaded to the Sun Web site http://java.sun.com/products/javawebstart/download-spec.html.
The following is an example of implementing a Java Web start with the simplest HelloWorld method, and the engineering Webstart directory structure is as follows:
The directory description is as follows:
Images: Store the icon file defined in the *.JNLP file
JAR: Store classes packaged jar file
JNLP: Storing *.JNLP description file
Src:java Source
Web-inf/classes:java the compiled class file
Webatart steps are established as follows:
1. Create a new Helloworld.java file under Webstart/src/jws:
Package JWs;
Import javax.swing.*;
public class HelloWorld {
Private JFrame JFrame;
Private JPanel JPanel;
Private JLabel label;
Public HelloWorld () {
JFrame = new JFrame ("HelloWorld Test Frame");
label = new JLabel ("Hello, world!");
JPanel = new JPanel ();
Jpanel.add (label);
Jframe.add (JPanel);
Jframe.pack ();
Jframe.setsize (400, 150);
Jframe.setlocation (400, 300);
Jframe.setvisible (TRUE);
Jframe.setdefaultcloseoperation (Jframe.exit_on_close);
}
Webstart The main method executed at startup
public static void Main (String args[]) {
New HelloWorld ();
}
}
Note: In the Main method it is entirely possible to write a new HelloWorld (), and only one Test statement is printed in the Main method
System.out.println ("This is test!");
For a simple test, the print results appear in the Step 7java console
2. Compile the Helloworld.java and execute the command in the Web-inf/classes directory:
Jar CVF Helloworld.jar Jws/*.class
After execution, copy the generated Helloworld.jar package to the Webstart/jar/jws directory.
(It's handy to pack in idea with a jar tool plug-in, which can be used in Eclipse Fatjar)
3. Extract the MNIFEST.MF from the Helloworld.jar/meta-inf and change the MNIFEST.MF content:
manifest-version:1.0
CREATED-BY:1.5.0_01 (Sun Microsystems Inc.)
For:
manifest-version:1.0
CREATED-BY:1.5.0_01 (Sun Microsystems Inc.)
Main-class:jws. HelloWorld
Then execute the command in the Web-inf/classes directory:
Jar UMF MANIFEST. MF Helloworld.jar
Update the new MNIFEST.MF into the Helloworld.jar package,
Note: If the <application-desc main-class= "JWs" in step 4 below. HelloWorld "/> Specified Main-class method, this step can be omitted.
4. Create a new HELLOWORLD.JNLP file in the WEBSTART/JNLP directory:
<?xml version= "1.0" encoding= "UTF-8"?>
<!--The CodeBase property indicates the top-level URL for the Search application resource, and the following Icon/jar elements are based on this URL .-->
<JNLP codebase= "Http://127.0.0.1:8081/webstart" >
<information>
<!--start Web start by entering "Javaws" or "Javaws-viewer" on the "Start"-"Run" menu, you will see the Webstart application that the client has installed-->
<!--title: application Title Vendor: Suppliers
The Title/vendor element must be displayed with the "javaws-viewer" command
Open Application Cache Viewer (Java application cache Viewer)-->
<title>HelloWorld</title>
<vendor>lively corporation</vendor>
<description>helloworld Test Example for webstart.</description>
<!--homepage: The URL of the relevant documentation for the application, such as Help file, is only description action-->
<!--icon Specifies that icons are displayed in the application cache viewer.
When you create a new Webstart shortcut to the desktop in the viewer, it also appears as a shortcut icon.
Only gif/jpeg formats are supported and other formats are not valid-->
<icon href= "./images/logo.jpg"/>
<!--Splash mentioned in the Sun's documentation that it would appear in the splash screen at webstart startup, but I didn't observe the--> due to the speed problem.
<icon kind= "Splash" href= "/images/logo.jpg"/>
<!--allow offline booting, you can use the Javaws-offline command-->
<offline-allowed/>
</information>
<resources>
<!--Specify the J2SE version that the client needs to install, with the following specified as 1.5 +,
If the version is 1.4, you will be prompted to update the J2SE version when the JNLP file is linked-->
<j2se version= "1.5+"/>
<!--Specify the jar file to download to the local (note that all files need to be packaged before they can be downloaded).
Can contain resource files, such as icons/configuration files, which can be obtained using the GetResource method-->
<jar href= "./jar/jws/helloworld.jar"/>
</resources>
<!--Application-desc must specify which class to execute in the jar file when Webstart starts-->
<application-desc main-class= "JWs. HelloWorld "/>
</jnlp>
Note:
Details of the syntax of the *.JNLP file can be queried on the Sun Web site http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/syntax.html
The detailed parameters of the Javaws command line can be queried on the Sun Web site http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/javaws.html#options