packaging and publishing of Java programs
Here is the main explanation of how to package the Java program into a standalone EXE package, the following method should be the best solution. The EXE package for Netduke is made using this scheme. In the operation of the procedure is still relatively simple, and strong versatility.
1. Program Packaging
First, the program into a jar package, packaging command: Jar CF package file name. jar *.class. The manifest file MANIFEST.MF in the package is then compiled.
manifest-version-Specifies the version number of the manifest text
Main-class-Specifies the entry class that the program runs. Note: Do not add class name extensions
2. No need to install JRE environment for user pc
A prerequisite for running Java programs is that the user's computer must first install the JRE environment. Although installing the JRE environment is very simple, after all, there is a little bit of a flaw. Here is a method that does not need to allow the user to install the JRE environment, and the following steps are implemented:
(1) Copy the "JRE" directory from the original JDK into the "D:\ project folder \java1.4.2" directory (java1.4.2 can also be replaced by another name).
(2) Uninstall the JDK and JRE from the native computer, which means that the Java Runtime environment is not installed on this machine.
(3) Modify batch file The command in Run.bat is "Start Java1.4.2\jre\bin\javaw-jar Netduke.jar", just add a relative path before JAVAW.
Double-click Run.bat to run this Java application on a computer that does not have a JRE environment installed.
3. Further improvement
1. Discard batch files (*.bat)
Running a program with a batch file does not seem professional enough, though it is sufficient to run the task. But habit is like a poison once infected it is very difficult to get rid of its influence, Windows rule people have been accustomed to running the extension is EXE program, with *.bat they will feel awkward.
We can use a free applet called Javalauncher to run Java programs instead of batch files. Javalauncher's Download URL is: http://www.rolemaker.dk/nonRoleMaker/javalauncher/marner_java_launcher.htm
The downloaded file is a compressed package named Javalauncher.zip, the extracted directory structure is as follows:
The 1.source directory contains the Javalauncher source program, which is written in C language.
2.changes.txt is a revised description of the new version
3. Launch.exe is the main program
4. Launcher.cfg is a configuration file
5.readme.txt is a few notes and examples
We only need to Launch.exe, launcher.cfg two files, copy the two files to the directory where the packaged files are located. Launcher.cfg is a text file with only three lines of content and modifies it as follows:
.
. \java1.4.2\jre\bin\javaw.exe
-jar Netduke.jar
The first line sets the directory that points to the jar package Netduke.jar, because Launch.exe and Netduke.jar are in a directory, so use "." That is the current directory.
The second line sets the path to Jre\bin\javaw.exe. To copy the JRE directory to the java1.4.2 subdirectory first
Once you have configured Launcher.cfg, double-click Launch.exe to run the Java application.
If you look at how Eclipse starts, you find Eclipse and javalauncher the same principle: Eclipse.exe is equivalent to Launch.exe,startup.jar equivalent to Netduke.jar. But Eclipse.exe not like Launch.exe to have commonality, so it does not *.cfg such a configuration file, but the startup information is solidified in the Eclipse.exe.
4. Landscaping icons
The icon for the Launch.exe file is too dull, so let's change it for a good show. To change the program's icon need to use a free software: Resource Hacker, it has the Chinese version, the download URL is:
http://www.users.on.net/johnson/resourcehacker/
The steps to replace the Launch.exe icon with resource hacker are as follows:
(1) Run resource Hacker.
(2) Click the main Menu "file → open" to load the Launch.exe into the program.
(3) Select "Icon →1→1030" on the left, then right-click the "1030" key and select "Replace Resource ...". Then click "Open New Icon file" in the pop-up window, select a satisfactory icon, then click the "Replace" button.
Note: Icon file can be exe, DLL, RES, ICO, the software can be extracted from EXE, DLL, res icon, this example is the Java mascot Duke.ico.
(4) Select "File → Save As", named NetDuke.exe.
Note: It is supposed to choose "save" is also possible, then resource hacker will be old Launch.exe back to Launch_original.exe. But perhaps there is a problem with the refresh, with "save" mode sometimes launch.exe cannot display a new icon, but sometimes it can.
(5) The final directory is shown below, and the icon for NetDuke.exe (aka Launch.exe renamed) is replaced by the Java icon. Double-click NetDuke.exe to run the Java application.
1.java1.4.2 (folder)
2.launcher.cfg
3.netduke.exe
4.netduke.jar
5. The final packaging
Before sending to the user, usually with WinZip or winrar all the files into a compressed package, and then the user gets the compressed package, after extracting it to run the program, the Eclipse software is this way.
In addition, we should pay attention to several points:
(1) The resources used in the Java application must require the absolute path to be written, otherwise there will be no resources found on the other machine. So in general, we should be careful when writing the program must use absolute path, for example: Toolkit.getdefaulttoolkit (). GetImage (GetClass (). getresource ("file name")); like this, it must be fine. Of course, if you want to pass the resources to the constructor, there is no way, for example: Netduke frame = new Netduke ("resources"); This is where we need to copy the resources to the project folder to package together.
(2) In general, our JRE has more than 60 m, so it is cumbersome to package with the program. So in order to properly lose the JRE, the specific practice is no longer cumbersome, we have not installed a JRE in the machine test, the JRE in the file after the removal of the program can be normal operation. There is also a Rt.jar this Java class Library also need a lot of felling.
Javaweb program package or exe execution file