I am using Eclipse to package it, but when executing the CMD window, I reported the error "There is no main manifest attribute in ActiveMQ.jar" when executing it.
I searched online and found that this is related to the MANIFEST.MF file. This file does not define the path of the class where the MAIN method is located. I can use it to open the jar package. As expected. There is only one line inside
Manifest-Version: 1.0
Main-Class needs to be added. In this example, add the following:
Main-Class: com.luoluo.TestUse.activemq.ActiveMQStateMain
Above, there are a few points to note:
1. Main-Class: There must be a space between com.luoluo.TestUse.activemq.ActiveMQStateMain, remember.
2. com.luoluo.TestUse.activemq is the package name of this class, and ActiveMQStateMain is the class name where the main method is located. Note: .java or .class is not required to be added afterwards.
3. If you do not quote a third-party package, you need to press Enter to let the cursor go to the next line. Otherwise, there will still be an error "There is no main manifest attribute in ActiveMQ.jar". If a third-party package is referenced, press Enter after Class-Path. In short, after specifying the relevant parameters, press Enter to let the cursor go to the next line.
The above only defines the main class. If a third-party package is referenced, the following error will be reported:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/activemq/broker/jmx/BrokerViewMBean
At this time, Class-Path needs to be defined in the MANIFEST.MF file. In this example, add the following:
Class-Path: lib/activemq-all-5.12.1.jar
Note: There is also a space between Class-Path and lib/activemq-all-5.12.1.jar.
At the same time, in the same level directory of the jar package, create a new lib folder and copy activemq-all-5.12.1.jar into it.
For example, in this example, the jar package is under C:/Users/Victor/Desktop, and you need to create a new lib folder in the C:/Users/Victor/Desktop directory and put the corresponding third package in it.
The former is a packaged jar package, and the latter is a lib folder, which contains a third-party jar package.
Finally, the contents in the MANIFEST.MF file are as follows:
The final execution result is as follows:
The above content is shared with you how Java quotes third-party jar packages when making jar packages. I hope you like it.