How to reference a third-party jar package when creating a jar package and a third-party jar package

Source: Internet
Author: User

How to reference a third-party jar package when creating a jar package and a third-party jar package

I use Eclipse for packaging, but when executing the command in the CMD window, the error "ActiveMQ. jar has no main list attribute" is reported.

I searched the internet and found this is related to the MANIFEST. MF file. The file does not define the path of the class where the MAIN method is located. open the jar package with good pressure. There is only one row in it

Manifest-Version: 1.0

You need to add Main-Class. In this example, add the following:

Main-Class: com.luoluo.TestUse.activemq.ActiveMQStateMain

Note the following points:

1. Main-Class: there must be a space in the middle of com. luoluo. TestUse. activemq. ActiveMQStateMain. Remember.

2. com. luoluo. TestUse. activemq is the package name of the class, and ActiveMQStateMain is the class name of the main method. Note: you do not need to add. java or. class later.

3. If a third-party package is not referenced, press enter to move the cursor to the next line. Otherwise, the error "no main list attribute in ActiveMQ. jar" is reported. If a third-party package is referenced, press Enter next to Class-Path. In short, after the related parameters are specified, press enter to move the cursor to the next line.

 

The above only defines the primary class. If a third-party package is referenced, the following error is reported:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/activemq/broker/jmx/BrokerViewMBean

In this case, you need to define the Class-Path in the MANIFEST. MF file. In this example, add the following:

Class-Path: lib/activemq-all-5.12.1.jar

Note: a space is also required between Class-Path and lib/activemq-all-5.12.1.jar.

At the same time, in the jar package directory at the same layer, create a new lib folder, copy the activemq-all-5.12.1.jar to it.

For example, in this example, if the jar package is under C: \ Users \ Victor \ Desktop, you must create a lib folder under the C: \ Users \ Victor \ Desktop directory, put the third package in it.

The former is the packaged jar package, and the latter is the lib folder, which contains a third-party jar package.

Finally, the content in the MANIFEST. MF file is as follows:

The final execution result is as follows:

 

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.