1

I am trying to make 2 different jars with maven project. I have specified the path of the classes using the main in them. I want to create 2 jar with different main runnable.
Here is what I tried to add:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>pf.super.Analyzer</mainClass>
                            <mainClass>pf.super.Trainer</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

After making the maven with clean and install as argument, I get to have to different jars but both show the same result. That means one main class is taken while the another isn't taken at all.
Kindly guide me where I am wrong and how I can resolve the problem?

Software Engineer
  • 15,457
  • 7
  • 74
  • 102
Jaffer Wilson
  • 7,029
  • 10
  • 62
  • 139
  • A manifest can only contain one main class entry. You must rethink your approach. – Thorbjørn Ravn Andersen Mar 06 '17 at 09:03
  • Possible duplicate of [Creating Two Executable Jars Using maven-assembly-plugin](http://stackoverflow.com/questions/15798936/creating-two-executable-jars-using-maven-assembly-plugin) – Stefano Zanini Mar 06 '17 at 09:03
  • 3
    First make two different modules which contains the Main class and create two separate jar files from it. Make the common classes a dependency.. – khmarbaise Mar 06 '17 at 09:20

1 Answers1

1

You can only have one default main method class. What you can do instead is

Define the main you want on the command line.

java -cp myjar.jar pf.super.Trainer

or you can have a main which starts/calls your other mains

public class Main {
    public static void main(String... args) {
        pf.super.Analyzer.main(args);
        pf.super.Trainer.main(args);
    }
}
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130