Jaffer Wilson
Jaffer Wilson

Reputation: 7273

Why maven did not make 2 Jar for 2 different main methods?

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?

Upvotes: 1

Views: 192

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533492

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);
    }
}

Upvotes: 1

Related Questions