简体   繁体   中英

How to generate one jar with different executable classes in maven2?

I have a big project that uses maven and I'm creating the project's jar. The problems is that the project has several classes that can be executed. How can I accomplish this?

Every time that I try to execute a class I get this message

java -jar library.jar ExecutableClass1 Failed to load Main-Class manifest attribute from library.jar

The manifest.mf file in your JAR can only have one Main-Class entry.

Main-Class: classname

The jar would then by executed by running below.

java -jar library.jar

If you have several "executables" that could be run then you can either pass command line parameters to the JAR and then run the correct code or you can generate multiple JAR files for each "executable".

A possible alternative to using the -jar switch is to explicitly start one of the "executables":

java -cp library.jar ExecutableClass1

If your jar has dependencies, then these will need adding to the classpath as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM