[Java Study Notes] program release

Source: Internet
Author: User

Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/

1. Notes
1) Suitable versions of JRE have been installed
2) complete Class
3) Data configuration file
4) executable commands

2. Basic operations on jar files

The jar file is actually a zip file, which can be operated by ZIP or unzip, but the JAR file contains special information. The jar command is used to operate jar files. It automatically generates a file named mantext and stores relevant information.
For example:
Rivers
Public class rivers {
Public static void main (string Arg []) {
System. Out. println (Mississippi. getname ());
System. Out. println (Amazon. getname ());
System. Out. println (Yukon. getname ());
}
}
-------------------------
Mississippi
Public class Mississippi {
Public static string getname (){
Return ("Mississippi ");
}
}
---------------------------
Amazon-like
Public class Amazon {
Public static string getname (){
Return ("amazon ");
}
}
---------------------------
Class Yukon
Public class Yukon {
Public static string getname (){
Return ("Yukon ");
}
}
Create mantext
Main-class: <space> rivers <press enter>
Specifies the class of the main function.
Class-path: burners. Jar
All classes in the burners. jar file are available when the JAR file is running.
Run the following command to create the JAR file: jar CFM wetlands. Jar mantext *. Class
Of course, if there is a subdirectory image, you can use jar CFM wetlands. Jar mantext *. Class Image
To package all the files and subfolders in the current directory into a jar package, and the contents in the package must be the same as those in the current directory
Jar CFM wetlands. jar *. Class-C images.
If you do not want to compress and package, use jar cfm0 wetlands. Jar mantext *. Class
You can use the following command to directly run the JAR file: Jave-jar wetlands. Jar
If the jar package is displayed, use jar TF wetlands. jar or jar tvf wetlands. jar.

3. the electronic signature of the JAR File

Private Key Encryption and Public Key decryption are mainly used for electronic authentication. The local file keystore stores information about the signature. Alias specifies the Certificate Name.
Create a key pair:
Keytool-genkeypair-keystore. keystore-alias moosebreath-validity 3650
(Valid within 10 years)
Sign the Java program:
Jarsigner-keystore. keystore wetlands. Jar moosebreath
Check whether the signature is signed:
Jarsigner-Certs-verify wetlands. Jar

4. Web Start release

1) configure the Web server: Open the Apache configuration file httpd. conf and find addtype and add the following line: addtype application/X-Java-JNLP-file. JNLP
2) package the program into a jar package
3) create a JNLP file-The JNLP application allows the application to access it through a Web browser like a standard Java applets, in addition, JNLP can be restricted to a secure sandbox on the client host )". Unlike applets, JNLP applications do not run in customers' browsers. On the contrary, Web browsers only serve as a starting point or installation tool for applications. The following is an example, which can be used as a template:
1. <? XML version = "1.0" encoding = "GBK"?>
2. <JNLP
3. <! -- File-compatible JNLP version -->
4. spec = "1.0 +"
5. <! -- Absolute position of the program. Other relative URLs are relative to this position -->
6. codebase = "http: // 210.43.32.199/Apple /"
7. <! -- Relative URL of this file -->
8. href = "draw. JNLP">
9. <information>
10. <! -- Program title -->
11. <title> drawing </title>
12. <! -- Program producer -->
13. <vendor> Kevin MA </vendor>
14. <! -- For more information about this program, the URL of this page will be displayed on the jaws application manager -->
15. 16. <! -- The following elements are displayed on Jaws -->
17. <description> drawing </description>
18. <description kind = "short">
19. A simple drawing software
20. </description>
21. <! -- Points to the URL of A jpg or GIF file. It is displayed as an icon in the jaws application manager. -->
22. <icon href = "images/draw.gif"/>
23. <! -- Declare that the program can be run without accessing the server after being downloaded -->
24. <offline-allowed>
25. </Information>
26. <Security>
27. <! -- The request grants sufficient permissions to access the local machine, which requires all jar
28. All are signed. This item is not required for programs that do not access the Local Machine
29. <all-permissions>
30. -->
31. </Security>
32. <resources>
33. <! -- Specifies the JRE version supported by the program. Multiple IDs can be specified and checked in priority -->
34. <j2se version = "1.4" type = "codeph" text = "/codeph"/>
35. <! -- Specify the relative URL of the JAR file containing code and data. -->
36. <jar href = "draw_applet.jar"/>
37. <! -- Specify the JAR file to be downloaded as needed
38. <jar href = "lib/backgrounds. Jar"/>
39. -->
40. </resources>
41. <! -- Specify the main class of the Startup Program -->
42. <application-Desc main-class = "draw. drawpic"/>
43. </JNLP>
4) create a link for this JNLP:
<A href = "colorpicker. JNLP"> colorpicker </a>
5) upload your application to the server
5. Notes
Purpose: Documentation, compiler instruction, and runtime check.
Example 1:
Public class annotateone {
@ Overrides
Public String tosting (){
Return ("one ");
}
}
This will check whether the override method is used during compilation. If not, an error will occur.
In addition, a warning can be cleared during compilation:
Import java. util. vector;
@ Suppresswarnings ("unchecked", "UNUSED", "Semicolon ")
Public class annotationfour {
Void show (){
Vector VEC = new vector ();
VEC. Add ("one ");
}
}
You can define your own Annotations:
Import java. Lang. annotation. incluented;
Import java. Lang. annotation. retention;
Import java. Lang. annotation. retentionpolicy;
@ Brief ented
@ Retention (retentionpolicy. runtime) // annotation Period
@ Interface copyright {// It is similar to creating a new interface file
String CSTR () Default "Copyright (c) 2007-2008 ";
String comp () Default "gnuhpc ";
Int version () default 1;
}
@ Copyrightvtc
Public class annotationfive {
Public int returnone (){
Return (1 );
}
}

 

Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/

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.