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: