About how to compile the Java program into .exe file. Usually answers only two, one is to make an executable JAR file package, then you can double-click on the same .chm document; and the other is to compile using Jet. But Jet is to buy with money, and it is said that Jet is not able to compile all Java programs into executables, and performance is also a discount. Therefore, the method of making executable JAR file packages is the best choice, let alone, it can maintain Java cross-platform feature.
JAR file package
The JAR file is Java Archive File, and the appraisal, its application is closely related to Java, a document format of Java. The JAR file is very similar to zip file - accurately, it is a zip file, so it is called a file package. The only difference between the JAR file and the ZIP file is to include a meta-inf / manifest.mf file in the content of the JAR file, which is automatically created when generating a JAR file. For example, if we have some files with the following directory structure: == `- Test` - Test.class Complicates it into a zip file Test.zip, the internal directory structure of this ZIP file is: Test.zip` - Test `- Test.class If we use Jar command to use Jar commands Test.jar, the internal directory structure of this JAR file is: Test.jar | - META-INF |` Manifest.mf `- Test` --Test.class 2. Creating an executable JAR file package to make an executable JAR file to publish your program is the most typical usage of the JAR file package. The Java program consists of several .class files. These .class files must be stored separately according to their own packages; need to specify all the root of all the packages used to the ClassPath environment variable or the -cp parameters of the java command before running; if you want to go to the console Use the java command to run, if you need to directly double-click Run, you must write Windows batch file (.bat) or Linux's shell program. Therefore, many people say that Java is a programming language that facilitates developers who have bitter users. Actually, if the developer can make an executable JAR file package to the user, it is convenient to use it. When you install JRE (Java Runtime Environment) under Windows, the installation file will map the .jar file to Javaw.exe. Then, for an executable JAR file package, users only need to double-click it to run the program, and read. Thechm document is as convenient (.chm documentation is opened by HH.exe). Then, the key now is how to create this executable JAR file package. Create an executable JAR file package, you need to use the JAR command with CVFM parameters, as as an example of the above Test directory, the command is as follows: Jar CVFM Test.jar Manifest.mf Test here Test.jar and Manifest.mf two files, respectively It is the corresponding parameter f and m, and its weight play in Manifest.mf. Because you want to create an executable JAR file package, it is not enough to deserve a manifest.mf file, because Manifest is the feature of the JAR file package, the executable JAR file package and the unforgable JAR file package contain manifest. The key is the Manifest, which can perform the JAR file package, which contains the main-class.
This is written in manifest as follows: main-class: Execute the main class full name (including the package name) For example, assume that the test.class in the above example belongs to the TEST package, and is an executable class (define public static Void main (String []) method), then this manifest.mf can be edited as follows: main-class: test.test
3. JAR command details JAR is installed with JDK, in the bin directory in the JDK installation directory, the file name under Windows is jar.exe, and the file name under Linux is JAR. It runs to use the Tools.jar file in the Lib directory in the JDK installation directory. However, in addition to installing JDK, we don't need to do anything, because Sun has helped us do well. We don't even need to put Tools.jar in the ClassPath. Use without any jar commands We can see the usage of JAR commands as follows: jar {ctxu} [vfm0m] [jar- file] [manifest- file] [-c directory] file name ... where {ctxu} is Jar The subcommand of the command, each JAR command can only contain one of the CTXU, which represents: -c Creating a new JAR file package -T listing the content list of the JAR file package -X expands the specified file of the JAR file package or all File -U update the option existing JAR file (add file to the JAR file) [VFM0M] can optionally, you can not choose, the option parameter of the JAR command is the selection of detailed report and print to standard Output -f Specifies the JAR file name, usually this parameter is a must-mode specifying the Manifest manifest file -0 stored, not compressed, which is not compressed, the JAR file package is larger than the volume of the parameter, but the speed is more Fast -m does not generate a list of all items (MANIFEST) files, this parameter ignores the -m parameter [JAR-file] needs to be generated, view, update, or unlocked JAR file package, it is the accessory parameter of the -f parameter [ Manifest- File] The Manifest list file, which is the accessory parameter of the -m parameter [-c Directory] indicates that the operation of the specified directory is executed. It is equivalent to using the CD command to turn this directory without carrying without -C parameter jar command, it can only be available when creating and updating the JAR file package. File name ... Specify a file / directory list, these files / directory are to add files / directories in the JAR file. If the directory is specified, then the JAR command will automatically put all the files and subdirectories in the directory in the package when the JAR command is packaged. Some examples will be used to illustrate the usage of JAR commands: 1) jar cf test.jar Test This command is not executed The process of the process, the execution result is a Test.jar file in the current directory. If the current directory already has Test.jar, then the file will be overwritten.
2) JAR CVF TEST.JAR TEST This command is the same as the result in the previous example, but due to the function of the V parameter, the package process is displayed, as follows: MANIFEST, the manifest) Add: TEST / (read = 0) (write = 0) (0%) Add: test / test.class (read = 7) (write = 6) (40%) 3) JAR CVFM TEST.JAR TEST This command is similar to 2) However, but there is no meta-inf / manifest file in the generated Test.jar. The information for the package process is also slightly different: increase: TEST / (read = 0) (write = 0) (store 0%) increase : Test / test.class (read = 7) (write = 6) (40%) 4) JAR CVFM TEST.JAR Manifest.mf Test Run Results and 2) Similar, display information is the same, just generate JAR The meta-inf / manifest content in the package is the content that contains manifest.mf. 5) JAR TF TEST.JAR In the case of Test.jar already exists, you can view the contents in Test.jar, such as 2) and 3) The resulting test.jar should be this command, the result is as follows; for 2) meta-inf / meta-inf / manifest.mf test / test / test.class For 3) Test / Test / Test.class 6) JAR TVF Test.jar In addition to the content displayed in 5), it also includes details of the package, such as: 0 Wed Jun 19 15:39:06 GMT 2002 Meta-INF / 86 WED JUN 19:39:06 GMT 2002 Meta-INF / MANIFEST.MF 0 WED JUN 19 15:33:04 GMT 2002 TEST / 7 WED JUN 19 15:33:04 GMT 2002 Test / Test.class 7) JAR XF Test.jar Unope Test.jar to the current Directory, no information, for 2) generated test.jar, the unlocked directory structure is as follows: == | - META- INF | `- Manifest` - Test `--Test.class Jar XVF Test.jar Run Results with 7) The same, for detailed information, such as: Creation: Meta-INF / Expansion: META-INF / Manifest.mf creation: test / expand: test / test.class 9) Jar uf test.jar manifest.mf Added file manifest.mf in Test.jar, this use JAR TF to view Test.jar to find Test.jar More than one manifest is more than the original. By the way, if you use the -m parameter and specify the manifest.mf file, then manifest.mf is used as a manifest file manifest, and its content will be added to Manifest; however, if it is added as a general file to the JAR file In the package, it is not different from general documents.
10) JAR UVF Test.jar Manifest.mf and 9) The result is the same, and there is a detailed information display, such as an increase: manifest.mf (read = 17) (write = 19) (compressed -11%) 4. About Some Tips for JAR Package 1) Use unzip to extract the JAR file When introducing the JAR file, the JAR file is actually a zip file, so you can use the commonly extracted ZIP files to extract the JAR file. , Such as WinD, WinRAR, etc. under Windows Unzip, etc. Using Winzip and WinRAR, the decompression is because they decompressed more intuitive and convenient. Use unzip because it can specify the target directory using the -d parameter when it decompresses. When decompressing a JAR file, it is not possible to use the JAR-C parameter to specify the decompressed target, because the -c parameter is only available when creating or updating the package. Then you need to extract the file to a specified directory, you need to copy this JAR file to the target directory, and then decompressed, trouble. If you use unzip, you don't need to be so troublesome, just you need to specify a -D parameter. Such as: unzip test.jar -d dest / 2) Creating a JAR file using Winzip or WinRAR and other tools to mention the JAR file is a ZIP file containing meta-inf / manifest, so you only need to create a tool such as Winzip, WinRAR. A zip compression package is required to add a Meta-INF directory containing the Manifest file in this zip compression package. For the case of using the -m parameter using the jar command, only the manifest is required to modify this manifest. 3) Use the JAR command to create a zip file Some Linux provides a unzip command, but there is no zip command, so you need to decompress the zip file, you can't create a zip file. To create a zip file, use the JAR command with the -m parameter, because the -m parameter indicates that the manifest list is not added when making the JAR package, then only needs to change the .jar extension in the specified target JAR file. The .zip extension, created is a unclatible ZIP file, such as the third example of the previous section): JAR CVFM TEST.ZIP TEST