About eclipse several ways to package Java app projects into jars and plug-in __java

Source: Internet
Author: User
Tags pack

Recommended Practices:

It is convenient to install a Fatjar plug-in, and the jar pack can be run, including referencing the external jar pack and other files, and can be easily referenced to the jar bag.

After installing the plug-in, click on the right button, export, should be in other, choose fat Jar exporter, and then their own slowly optimistic about some options on the line.

The second method: (I tried many times, the jar package can be run, but when the jar is transformed into a different directory, there will be a hint of missing the relevant jar package, do not recommend the practice)

The Java project hits jar packs into 2 different scenarios:

A Java project does not import a third-party jar package

It's easier to pack at this point:

1. First open the project in Eclipse, right click on the project, select "Export";
2. Choose Java/jar File,next;
3. Select the resources to export you want to include the project folder, some unnecessary folders need not put in, so as not to increase space;
Here are a few options:
* Export generated class files and resources for exporting only generated. class and other resource files
* Export all output folders for checked projects indicates that all folders for the selected item are exported
* Export Java source file and Resouces indicates that the exported jar package will contain your source code *.java, if you do not want to leak the source, then do not choose this
* Export refactorings for checked projects include some refactoring information files
Select the path of the exported jar in the Select the export destination, Next
4. On the next page, you can choose whether to export *.class files that contain warning warning or error errors. You don't have to ignore him, Next.
5. The next page can be configured with a few items. (If the project does not introduce a third-party jar package, we use the system default option to Ok,main class must be set to be the Main method entry class for your project)
* Generate The manifest file is the system to help us automatically generate MANIFEST.MF files, if your project does not reference other Class-path, you can choose this one.
* Use existing mainfest from workspace. This is the choice we can customize. MF file, formatted as written above.
* Seal content. To encapsulate the entire jar or the specified package packet
* Main class. Here you can choose your program entry, and the future packaged jar is the result of your entry class.
Finally finish, finish. ......

Second, the Java project has imported a Third-party jar package (for example, the project has imported Sqlserver2005.jar package)

Packing is a little more complicated at this point:

The previous 4 steps are the same as the above, but the 5th step is to select the use existing mainfest from workspace option and select a MANIFEST.MF file that you created because the system defaults to the Generate Manifest the file option, which does not use a third-party jar bundle to enter a Java project-generated jar package.

Custom configuration file MANIFEST.MF:

First create a MANIFEST.MF file under the root directory of the project

Next, open the file in Notepad and edit:

For example:
manifest-version:1.0
Main-class:studentmanager_test
Class-path:sqlserver2005.jar
Manifest-version refers to the version number of the program, Main-class refers to the Main method entry class of the program, and Slass-path specifies the location of the foreign jar package. Please note that if our project is packaged and Project.jar, then as defined above, it should be Project.jar in the same-level directory has the relevant jar package (that is, Sqlserver2005.jar, if you have introduced a number of Third-party jar packages, you can be separated by a space) placed inside. Otherwise, an error exception in thread "main" Java.lang.NoClassDefFoundError will appear.

There are a few things to be aware of:

1: The last line in the configuration file must be wrapped.

manifest-version:1.0
Main-class:src.guanyy.timetaskcreatedata
Class-path:sqlserver2005.jar

2:main-class: The Main function in can take a package: for example:

Main-class: (a space) src.guanyy.TimeTaskCreateData

Middle space Don't forget

3:class-path in the following wording:

Class-path: (one space) Lib\mysql-connector-java-5.1.18-bin.jar (one space) other jar packages

Class-path:lib\mysql-connector-java-5.1.18-bin.jar lib\.

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.