Packaging of Java projects in eclipse

Source: Internet
Author: User

1. To make the project into a jar:


1.1 to package a project into a jar file, there are many ways to package it with Eclipse's own packaged tools, ant, or to build a jar with Eclipse's export. After trying, I don't recommend using ant to package, because I want to write my own XML scripting language, but also add some external jar, so I did not hit several times.

Here are two ways to generate a jar:


1.2 The first one is the export function with Eclpise. Right-click on the item you want to package, select Export, and in the window, select the Jar file in Java. After the next window has automatically selected the items to be packaged, the user can click the plus sign to see what is packaged in the project. In the following JAR file, set the output directory where you packaged the generated jar files, next select the use existing manifest from workspace in the window that appears, and click Browse directly behind the main class below. It automatically lists the classes in your project that have the main function main. Select the main class and click Finish to generate the jar file. In this note, this packaging method does not bring the external jar package in the project, because it is also to write some scripting language, not deep research. So some of the generated jars are not executable.


1.3 The second method is to use a third-party plug-in eclipse Fatjar to generate jar files, but also I think the simplest and most convenient way to build. First download some plugins from the internet, unzip is a plugins folder, there is only one folder, my is "net.sf.fjep.fatjar_0.0.24" copy it to Eclipser Plugins folder, the plug-in is installed successfully, Restart Eclipse Right-click on the project to see a "Build Fat Jar" with a green "+" sign in front of it, and you can use this plugin to package your project. In the first interface jar-name add the jar file name to be generated, mine is "Camp_fat.jar". After Main-class point Browse like export it will also list the main class in your project, after the selection of the other default, Next will list all the content you want to package, the advantage of this plugin is that you can also enter the external jar in your project, there are three first items, which export Ant is a build.xml script file that makes it easier for the user to modify the script later, and the other two buttons are useless. There's nothing to point here, just point to finish to generate the jar file.

2. Make the jar into an. exe file:


2.1 Although the jar file is now ready to execute. The files that generate the. exe are implemented in two ways, and the packaging tools used are J2ewiz and exe4j, and their differences will be reflected in my presentation below.


2.2 First J2ewiz, the software is green, without installation, decompression can be run directly, but the software generated by the. exe file is not cross-platform. The first thing to run this program is to enter the jar file to be packaged, and we browse the jar to select the "Camp_fat.jar" project file we generated earlier with Fatjar (see 1.3), the following option is the JRE version that prompts the user for the minimum requirements, typically 1.3. Next, because our dormitory management system is a graphical interface, so Select "Windows window Program" Here next it is also automatically generated to execute the main class, you just choose to. The following box allows you to select the picture that your launcher displays. After the next step, this window can be selected according to personal preference. Next, if your program has any dependencies on the external jar file, you can add it from here, but because the previous fatjar was in the Camp_fat.jar package with the three outer classes of the database that were used by our project, there is no need to add it here. If you have previously used export-hit jar packages, then you need to add the three-database package (see 1.2). The next step is to add the. exe file name that you want to generate, select a program icon, and then generate the. exe files after the next step. Double-click the generated. exe file to see the effect, the EXE file is not out of the JDK environment, and can not be used across platforms, only for team members to test the use.


2.3 Below goes to the most critical, how to package a cross-platform. exe file. The software used is exe4j, I use the V4.0 version, this software needs to be cracked. Running the left window after installation is marked with 10 steps, but the packaging process is also very simple. The first step is completely skipped, the second step of the next we choose "jar in EXE mode" is to choose we already have a well-made jar file. The 3rd step above is the project name, can be filled out, the following one write you want to be packaged exe file output directory my is "desktop \project\". 4th step, because my demo program is graphics, so choose the first one, if your program is the console, then select the second, executable name write the name of the. exe file you are about to generate, icon file can choose to generate the file icons. 5th step, forget the above, first click the green "+" in the following, in the pop-up window point Archive, and then find the first already done Camp_fat.jar (see 1.3) file, "OK" back, in the following class path, the jar file path appears, Click to find the class where main is located in the main class column above. 6th, the JRE version of your system, generally fill in a 1.3, the following 1.6 Click on the advanced options here, select Search sequence. This is because we have to package the JDK environment so that the program can be used across platforms. First copy the JRE directory under your system's JDK to the "desktop \project\jre" in the output directory of your. exe file, and then go back to exe4j to remove all items from the list in the pop-up window. I have three items, a registry, a Java environment variable, a JDK environment variable, do not. Then click the Green "+", select directory and select the root of the JRE, my "desktop \project\jre" is the copy of the directory, after the selection exe4j pop-up windows in the directory will display ". \jre". Click OK to close the window and return to the main window of exe4j to see the path you just added. Click Advanced Options from the left window of the main window and select the preferred VM, select the client hostspot vm in the pop-up window, and click the Next button to continue. 7, 8 step is some personality settings by default. 9th Step after compiling the 10th step you click on the "click here to Start the application" button to see the program run effect, and then click "Seave as" to save a exe4j generated a file, anywhere can be stored anywhere, and our. exe processThe sequence is irrelevant. The whole production process is complete.  

Packaging of Java projects in eclipse

Related Article

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.