Generate two jar with the same maven project

2019-02-18 00:52发布

问题:

I would like to generate two jars from the same maven project when executing a mvn clean install. The only difference between the two jars, will be the content of the META-INF folder.

For the moment, I've my-app.jar, I would like to have now my-jar-xxx.jar and my-jar-yyy.jar. How can I achieve this ?

Regards.

回答1:

You should not be creating two maven jars from the same maven project. Why? This sonatype blog post should explain.

The same article also explains two ways in which you can still do it, if you want to

  • Using profiles
  • By doing two executions of maven jar plugin

Here is the related stackoverflow post as well.



回答2:

First of all +1 for Raghuram recommendation. In his linked sonatype blog you get hints about doing what you want using the classifier to distinguish between your two jars. The jars belong to the same artifact in this case.

You can also use two different poms for two different builds and call

mvn -f pom-xxx.xml clean install
mvn -f pom-yyy.xml clean install

In each pom you can specify an own artifactId. That separates both artifacts a bit more than the classifier solution does.

Nevertheless the advice not to do this seems reasonable and I would follow the parent/module project layout suggestion.