Java packaging)

Source: Internet
Author: User

The general idea is to first compress the jar into an EXE. Focus on the content in 1.3 and 2.3.

1. compress the project into jar:
1.1 There are many methods to package a project into a jar file. You can use ant, the packaging tool that comes with Eclipse, or use export of eclipse to generate a jar file. After trying, I do not recommend using ant to package. Because I have to write the XML script language myself and add some external jar files, I have not completed it several times.


1.2 here we will introduce two methods to generate jar. The first is to use the export function of eclpise. Right-click the project to be packaged, select export, and select JAR file in Java in the window. The project to be packaged is automatically selected in the window after next. You can click the plus sign to view the package content in the project. In the following JAR file, set the output directory of the JAR file you have packaged and generated. In the displayed window, select use existing manifest from workspace and Click Browse directly after the main class, it will automatically list the classes with the main function in your project. Select the main class and click Finish to generate the JAR file. It is explained that this packaging method cannot include external jar packages in the project, because it is also necessary to write some scripting languages, which has not been studied in depth. Therefore, some generated jar files cannot be executed.
1.3 The second method is to use a third-party plug-in fatjar of eclipse to generate a jar file. It is also the simplest and most convenient method for generating a jar file. First download some plug-ins from the Internet, decompress the package, and it is a plugins folder, which contains only one folder, my "net. SF. fjep. fatjar_0.0.24 "copy it to the eclipser plugins folder, and the plug-in is successfully installed, restart eclipse, right-click the project, and you will see an extra "build fat jar" with a green "+" number in front. Then you can use this plug-in to package your project. Add the JAR file name to the jar-name on the first interface. My name is "camp_fat.jar ". After the main-class, Click Browse. It will also list the main classes in your project like the export. After selecting Other Default classes, next will list all the content you want to package, the advantage of this plug-in is that you can also include the external jar in your project. There are three first items, in which export ant generates build. XML script file, so that you can modify the script later. The other two buttons are useless. Click Finish to generate the JAR file.
2.compress jars into the. exe file:
2.1 although the JAR file can be executed at this time. The file generated by .exe is implemented in two ways. The packaging tools j2ewiz and exe4j are used. Their differences will be reflected in my introduction below.
2.2 is j2ewiz first. This software is green and does not need to be installed. It can be directly run after decompression, but the. exe file generated by this software is not cross-platform. To run this program, first enter the JAR file to be packaged. We will browse the JAR file and select the "camp_fat.jar" project file generated by fatjar (see section 1.3 ), the following option indicates the minimum required JRE version. Generally, 1.3 is used. Next, because our dormitory management system is a graphical interface, select "Windows window program" here. Next, it also automatically generates the main class to be executed. You only need to select it. In the following selection box, you can select the image displayed by the Startup Program. Next, you can select this window based on your preferences. Next, if your program has any dependent external jar files, you can add them here, however, because the fatjar file used by our project has imported the external classes of the three connected databases into the camp_fat.jar package, you do not need to add them here. If you used the jar package using export, you need to add the three database packages here (see section 1.2 ). The next step is the name of the. exe file to be generated. You can select another program icon. The next step is to generate the. exe file and click Finish. You can see the running effect of the. exe file generated in double-click mode. This type of EXE file is not isolated from the JDK environment and cannot be used across platforms. It can only be used for testing by group members.
2.3. The software used is exe4j, and I use v4.0. This software needs to be cracked. After installation, the Left window is marked with ten steps. In fact, the packaging process is very simple. The first step is skipped completely. Click Next. In the second step, select "jar in EXE mode" to select the JAR file that we have prepared. In step 2, the project name is above. You can enter it as needed. The following is the directory that you want to output the packaged EXE file. My name is "Desktop \ project \". Step 2: Because my demo program is graphical, select the first one. If your program is in the console, select the second one. executable namewrite the name Of the. exe file to be generated, icon file: select the icon for generating the file. Step 2: Do not worry about the above. First click the green "+" number below, and then click archive in the pop-up window. Then find the camp_fat.jar file that has been prepared at the beginning (see 5th for details, "OK" is returned. After the JAR file path appears in the following class path, click in the main class column above to find the class where main is located. Step 2: Enter 6th for the JRE version of your system. Enter 1.3 below. Click Advanced options here and select search sequence. This is because we need to package the JDK environment so that the program can be used across platforms. First, copy the jre under your system JDK to the "Desktop \ project \ JRE" under the output directory of your .exe file, and then return to the exe4j window to delete all the items in the list. I have three items, one registry, one Java environment variable, and one JDK environment variable. Click "+", select directory, and select the JRE root directory. My "Desktop \ project \ JRE" is the directory after copy, after selection, the directory in the exe4j pop-up window will display ". \ JRE ". Click OK to close the window and return to the main exe4j window. Then you can see the newly added path. Click Advanced options in the left-side window of the Main Window, select preferred Vm, select client hostspot VM in the pop-up window, and click Next to continue. Step 7 and Step 8 are some default settings. After completing the compilation in step 2, click the "Click here to start the application" button to see the program running effect. Then click "seave asave to save an exe4jfile, which is independent of our .exe program. The entire production process is complete.

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.