I have a Java project with multiple executables using the same classes. I currently have maven install set up to create a standalone executable jar for each main class, with all dependencies contained. I would like to instead have it all in one jar, as there's a huge amount of reuse. When I tried to do this previously, I got a complaint about a lack of a manifest file, so I tried this approach instead.
How do I need to set up my pom.xml, and how would I then specify which main class to use when launching in java on command line?
Ideally the user of the jar would only be able to specify the explicitly allowed main classes, as there are test main classes I have I don't want them to be able to use.
Another solution that would work would be to have all of the classes contained in a non-executable jar, and then to have a bunch of executable jars that each have a specified main class, but they all have access to the non-executable jar.
The relevant part of my pom.xml looks like this:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>build-a</id> <configuration> <archive> <manifest> <mainClass>path.to.MainClassA</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <finalName>MainClassA</finalName> </configuration> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> <execution> <id>build-b</id> <configuration> <archive> <manifest> <mainClass>path.to.MainClassB</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <finalName>MainClassB</finalName> </configuration> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>