Packaging and distribution of Java application projects

Source: Internet
Author: User

Java Application project packaging and distribution    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 make the program into JAR package, Package command: Jar CF package file name. jar *.class. The manifest file MANIFEST.MF in the package is then compiled.          Manifest-version-Specify the version number of the manifest file          Main-class-Specifies the entry class that the program runs. Note: Do not add class extension  2 after the name of the classes. Make the user's PC unnecessary to install JRE environment          There is a prerequisite for running Java programs: 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, which is implemented as follows:       (1) Copy the "JRE" directory from the original JDK to the "D:\ project folder \java1.4.2" Directory (java1.4.2 can also be replaced by other names).        (2) Uninstall the JDK and JRE from the native computer, which means that the Java Runtime environment is not installed on this computer.        (3) Modify batch file Run.bat the command is "start Java1.4.2\jre\bin\javaw-jar Netduke.jar", Just add a relative path before the JAVAW.        Double-click Run.bat to run this Java application on a computer that does not have a JRE environment installed.  3. Further improvements          1, Discard batch files (*.bat)        Use batch file to run the program does not seem professional, Although it is sufficient to complete the task of running. But habits are like a poison that's hard to get rid of once it's infected.Influence, the people under the windows rule already used to run the extension is EXE's 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:[url]http://www.rolemaker.dk/nonrolemaker/javalauncher/marner_java_launcher.htm[/url]            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        2.changes.txt is the new revision description        3. Launch.exe is the main program        4. Launcher.cfg is profile        5.readme.txt are some instructions and examples        We only need launch.exe, Launcher.cfg two files, copy the two files to the same directory as the packaged files. 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         & nbsp; 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.        Second line set point to Jre\bin\jThe path of the Avaw.exe. To first copy the JRE directory to the java1.4.2 subdirectory   Configure LAUNCHER.CFG, double-click Launch.exe to run the Java application.        If the tenant studies how eclipse is started, Discover the same principles of Eclipse and Javalauncher: Eclipse.exe equals 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           launch.exe files The icon is too dull, 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:       [url]http://www.users.on.net/ johnson/resourcehacker/[/url]           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.          NOTES: PressSaid choose "Save" is also possible, then resource hacker will 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 catalogue 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 & nbsp          3.NetDuke.exe            4.netduke.jar 5. The final package            before sending to the user, usually with WinZip or winrar all the files into a compressed package, and then the user gets the package, after the decompression to run the program, This is how Eclipse software works.        Other points to note:       (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) Generally our JRE has more than 60 m, so it is cumbersome to package with the program. So in order to properly weight the JRE, the specific practice is no longer cumbersome, we are in a machine has not installed the JRE test,If a file in the JRE is deleted, the program will run normally. There is also a Rt.jar this Java class Library also need a lot of felling.          This allows you to get an EXE package that satisfies you, without the use of other software. Hope to be of help to everyone.

Package and release of Java application projects

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.