When an external jar package is referenced (j2se), the JAR file is generated.

Source: Internet
Author: User
1. When the project does not reference the external jar package (j2se)

Select project ----> right-click, export... ---> JAVA ---> select JAR file ---> next --> select the path and name of JAR file --> next --- Select Main class ---> finish.

 

2. j2se)

Solution 1
When other external jar packages are referenced in the project, eclipse does not support exporting the external jar package at the same time, so it is more troublesome. The specific steps are as follows:
1. Generate the manifest file:
Select project ----> right-click, export... ---> JAVA ---> select JAR file ---> next --> select the path and name of JAR file --> next --- Select Main class ---> finish. At this time, the window for selecting the main class is displayed, but the main class is not selected here. Select generate the manifest file (generate the inventory file) at the top ), click Save the manifest in the workspace (Save the list in the workspace), and enter the file name in manifest file (list file), for example,/testproject/main, (testproject is the project name and main is manifest.
File Name) Click Finish.

An error occurs when the generated JAR file is run: Couldn't find main class

2. Return to the project and open the generated main. Enter the following information here:
Manifest-version: 1.0
Main-class: COM. pacong. Convert. Auto. propertes. convertautoproperties
Class-path: jxl. Jar
Among them, manifest-version: 1.0 is the version number of the newly generated manifest;
Main-class: COM. pacong. Convert. Auto. propertes. convertautoproperties is the class where the main class is located;
Class-path: jxl. jar is the name of the external jar package, which indicates the path and name of the external jar package to be used.
After completing the above steps, you can export the jar package with the external jar package.

3. select project ---> right-click, export ---> JAVA ---> JAR file ---> select the path and name of JAR file ---> next, at this time, I came to the window for Selecting Main class, but I didn't select main class here. I chose use existing manifest from workspace and selected the generated main in manifest file:, for example: /testproject/Main, click Finish, and the result is complete. Assume that the generated jar package is named test. jar, then the jxl. jar and test. jar is located in the same directory.

Do not select the main. MF and manifest files. Select the existing manifest file later. When writing manifest:

Manifest-version: 1.0
Main-class: COM. Test. gameframe; Class: there must be only one space at the end.
Class-path: nimrodlf-1.2.jar liquidlnf. jar; path must be followed by only one space

In addition, you must note that there will be a direct space after main-class, class-path, etc. Otherwise, the system will prompt a format error.

There must be a line break and no space.This is also worth noting. Otherwise, the system still prompts no mainclass

Jar creation failed

Detail: Invalid Header field

When you use export runnable JAR file, the jxl. Jar introduced in class-path must be in the same directory as test. jar. Relatively simple.
4. Notes:
To run the generated jar in the command line, run the following command:
C: \ Documents ents and Settings \ Administrator \ Desktop> JAVA-jar test. Jar
If the jar contains some system. Out. prinln statements, run the following command to view the printed content:
C: \ Documents ents and Settings \ Administrator \ Desktop> JAVA-jar test. Jar> log.txt
The output information will be printed to log.txt. Of course, log.txt is automatically generated and located in the same directory as test. jar.
You can also create a new start. BAT file, after creation; right-click --- edit, enter: Java-jar test. jar> log.txt; double-click Start. BAT to run test. jar.
You need to import the edisk package to this directory.

Solution 2
Copy the third-party package directly to JRE/lib/EXT/In the JDK installation directory. At this time, we need to restart eclipse, in this way, the package can be loaded into the Automatically Generated System Library. At this time, the jar package is packaged according to the above method.

Open the generated JAR file. If it still cannot run, it may be that JDK and JRE are installed on your machine at the same time. This is to copy a third-party package directlyJREInstall JRE/lib/EXT/in the directory. This is because the eclipse runtime depends on the virtual machine in the JDK, but after packaging, the runtime depends on the virtual machine in the JRE. (This article is a reprinted article for me, this part is my own test conclusion)

 

Solution 3: Use the fat jar plug-in to package a project that references an external jar package (j2se)

1. If you use APIs or other ancillary resources provided by a third party during program development, you must export the third-party files when exporting and generating jar files, otherwise, your program running will not reach the desired result.

You can use the fat jar plug-in to generate jar, fat jar download address: http://sourceforge.net/projects/fjep/ file is net.sf.fjep.fatjar_0.0.31.zip, after decompression you will see the net. SF. fjep. fatjar_0.0.0.31.jar file in the plugins folder
Jar ).
Plug-in installation: copy the fat JAR file to the Plugins under your eclipse directory .. restart your eclipse platform and check window --- preferences. If the pop-up window contains fat jar preferences, it indicates that you have installed the program successfully. If this item is not installed successfully, perform the following steps: Go to configuration --- org under your eclipse directory. eclipse. update and delete platform. XML file, and then restart eclipse. view window --- preferences and you will find Fat
Jar preferences. congratulations, you have successfully installed 2. right-click your project, select build fat jar from the options list, and click browser (main-class select your main class) --- next --- finish (select the resources you need to package together, and select all by default ). the jar file is generated in your project. run it and everything goes smoothly.

2. package with fat jar: Right-click your project and select build fat jar from the options list. The pop-up window is very friendly and easy to use at a glance, click browser (main-class select your main class) --- next --- finish (check the resources you need to package together, and select all by default ). the jar file is generated in your project. run it and everything goes smoothly.

I copied the plug-in to inin, deleted the platform.xmlfile, and started using eclipse.exe-clean. The plug-in cannot be installed. I don't know what's going on.

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.