Tag:io use ar java file sp on c linux
Can the application program written in Java eventually form an EXE-like executable file that can only be run with the command line?
---------------------------------------------------------------
There are usually two kinds, one is to make an executable jar file package, You can then double-click to run as a. chm document, and the other is to use jet to compile. But jet is buying it, and it is said that jet is not able to compile all of the Java programs into executable files, and performance has to be discounted. So, the best way to make the executable jar file package is to keep the Java cross-platform feature. &NBSP
Look at what a jar package is:
1. JAR file package the
Jar file is Java Archive files, as implies, its application is related to Java, is a Java document format. The jar file is very similar to a zip file--exactly, it is a zip file, so call it a file package. The only difference between a jar file and a zip file is that it contains a meta-inf/manifest in the contents of the jar file. MF file, this file is created automatically when the jar file is generated. For example, if we have some files with the following directory structure:
==
--test
--test.class
Compress it into a zip file test.zip, the internal directory structure of this zip file is:
test.zip
'--test
'--test.class
If we use the JDK jar command to make it into a jar file package Test.jar, the internal directory structure of this jar file is:
test.jar
|--meta-inf
| '--MANIFEST. mf
'--test
'--test.class
2. Create an executable jar package
Creating an executable jar file package to publish your program is the most typical use of jar packages.
A Java program is made up of several. class files. These. class files must be classified according to the package they belong to, and the root directory of all the packages used should be assigned to the CLASSPATH environment variable or the-CP parameter of the Java command, and the runtime must go down to the console using Java command to run, if you need to double-click to run the Windows should be written Batch file (. bat) or a shell program for Linux. As a result, many people say that Java is a user-friendly programming language for developers.
In fact, if the developer can make an executable jar file package to the user, then the user is convenient to use. When installing the JRE (Java Runtime Environment) under Windows, the installation file maps the. jar file to Javaw.exe open. Then, for an executable jar package, the user can simply double-click on it to run the program, as easily as reading the. chm document (. CHM documents are opened by default by hh.exe). The key now, then, is how to create this executable jar file package.
To create the executable jar package, you need to use the jar command with the CVFM parameter, as an example of the test directory above, the command is as follows:
Jar CVFM Test.jar MANIFEST.MF test
Here Test.jar and manifest.mf two files, respectively, corresponding to the parameters F and M, whose plays are in MANIFEST.MF. Because to create an executable jar package, it is not sufficient to specify a MANIFEST.MF file, because manifest is a feature of the jar package, both the executable jar package and the non-executable jar package contain manifest. The key is to execute the manifest of the jar file package, which contains the Main-class. This is written in manifest in the following format:
Main-class: Executable main class full name (including package name)
For example, assuming that the test.class in the previous example belongs to the test package and is an executable class (which defines the public static void Main (string[]) method, then this MANIFEST.MF can be edited as follows:
Main-class:test. Test < Enter >
This manifest.mf can be placed in any location, or it can be another file name, only need to have main-class:test. Test line, and the line ends with a carriage return character. After creating the MANIFEST.MF file, our directory structure becomes:
==
|--Test
| '--Test.class
'--MANIFEST.MF
At this point, you need to go to the parent directory of the test directory to use the JAR command to create the jar file package. That is, in the directory tree using the "= =" In that directory, use the following command:
Jar CVFM Test.jar MANIFEST.MF test
The Test.jar is then created in the "= =" directory, and this test.jar is the jar file package that is executed. The runtime only needs to use the Java-jar test.jar command.
It is important to note that the jar package created needs to contain the complete directory structure corresponding to the Java program's package structure, as in the previous example. The class specified by Main-class must also be a complete class name that contains the package path, as in the previous example, test. Test, and you can use Java < class name > to run this class without hitting the jar package, which is the Java test in the previous example. Test can be run correctly (of course, in the CLASSPATH correct case).
Java Build jar Package