jos
jos

Reputation: 1092

how to create jar for specific packages maven

I am working on a maven project. I want to create jar for the specific packages This is the project structure, I want to create jar containing only dca and common how do i achieve this.

myproject
|
--src
   |
   --main
        |
        --java
           |
           --common
           --dca
           --model
       --resources
   --test
--pom.xml

Can i achive this using maven-jar-plugin

Upvotes: 3

Views: 2532

Answers (2)

mthmulders
mthmulders

Reputation: 9705

You could seperate your project into submodules, where you have two submodules:

  • common
  • dca

These submodules would be seperate Maven artifacts in the same groupId as you currently have. Any module containing submodules must be packaged as pom, and hence cannot contain source code itself.

Code that depends on either package (for example, some kind of user interface, or web components) would reside in another submodule, say web or gui, and that submodule would have a Maven dependency on the common or dca artifact.

Summarising, your structure would look like this:

  • root --> packaging pom
    • web --> packaging war
    • gui --> packaging jar
    • other --> packaging pom
      • dca --> packaging jar
      • common --> packaging jar

Upvotes: 2

Adi
Adi

Reputation: 2394

maven-jar-plugin can be customized to include / exclude specific file. You can achieve this by configuring in pom.xml like below.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
.
.
<configuration>
    <excludes>
        <exclude>**/model/*</exclude>
    </excludes>
</configuration> 
.
.
</plugin>

Upvotes: 3

Related Questions