Creating multiple jars using single pom file

Usually maven pom.xml allows you to create only one artifact for which it is created. Sometimes you may required to create more than artifact (jar).

One scenario which I thought it would be useful is, you have a project which has all interfaces and implementations and you need to share the interfaces with other teams or components. The best approach will be to create interfaces and implementation as different projects and create respective artifact.

But there are case where you can't create multiple projects. I had a same case, where we had some interfaces inside this project which is shared with other projects. Unfortunately the other project has a reference to the main project also.

To create multiple jars from a single maven project, these are the steps,

1. Move all the files needed for first jar (interfaces in my case) under one package.
2. Move all other files needed for next jar (implementation in my case) under another package.

The following plugin statement in your pom.xml will generate two jar files with respective files.

In simple, You group the files under packages instead of different projects.