The problem cannot be found in the third-party jar package referenced by the jar package in eclipse.

Source: Internet
Author: User

During the project process, use eclipse to compress a jar package and use export --> JAVA --> JAR file. In my jar package, a third-party jar package, such as log4j, I also encountered this problem:

 

Http://zhidao.baidu.com/question/48376665.html

 

"Other jar packages are referenced in my program.
Running normally in eclipse
I want to create a jar package for my program.
During packaging, the referenced package is also included.
The package I referenced is always not found in the runable program"
 
Baidu knows that the best answer is as follows:
 
Create a new META-INF folder under your project folder
The file content of manifest. mf is as large as follows:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.5.0_06-57 ("Apple Computer, Inc.")
Built-By: hani
Main-Class: com.opensymphony.workflow.designer.Launcher
Class-Path: looks.jar forms.jar syntax.jar jgraph.jar foxtrot.jar osworkflow-2.8.0.jar oscore-2.2.5.jar
 
Main-class is the class you want to run.
Class-path: the package you want to introduce
Use eclipse to export the JAR file, select
user existing manifest from workspace
Manifest file:/your project name/src/META-INF/manifest. MF
Click Finish. This should work.
 
According to the above statement, I created a folder named META-INF under the SRC folder of my project, which created a file named manifest. MF, the content of which is as follows:
 

Manifest-Version: 1.0
Main-Class: com.sgfs.udp.client.ClientMain
Class-Path: ./lib/log4j-1.2.15.jar
 
Then, right-click the project and choose export --> JAVA file to export the jar package. What you need to do is to export the JAR file directory. For example, I put it in C: /sgfsudpclient directory, create a folder named Lib, and then add manifest. in the MF File class-path: Put the specified log4j-1.2.15.jar inside. The directory structure is as follows:
 
 
In this case, OK. Maybe you may think this method is not very good. Can you automatically include the referenced jar package in the package ??, In the end, we only need a jar file which can be run in any place. Yes, fatjar (the fat jar Eclipse plug-in is a deployment-tool which deploys an eclipse Java-project into one executable jar .), complete the operation by referring to the following article.
Eclipse jar package, plug-in fatjar Installation and Use (http://blog.csdn.net/jikeyzhang/archive/2009/10/27/4731968.aspx)
 
Fatjar Project address: http://fjep.sourceforge.net/
 
The summary in the above article is as follows: Generally, You can package SRC export => JAR file. To package SRC resources together, you must use fatjar => export... => fatjar.
The brief operation instructions are as follows:
Right-click your project and select build fat jar as follows:
 

In the pop-up window, select the main-class to be run, as shown below:
 
Click Next. On the next page, select the third-party jar package to be used, as shown below:
 

 
Click Finish to generate the JAR file.
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.