Search code examples
javaeclipsemavenmaven-pluginoverlays

How to use maven profile and overlays to build and package with specified project from multiple?


I have one web project called MyWebProject which having sub modules also and packaging as POM, I have other two simple java project called SimpleJavaProject1 and SimpleJavaProject2 which having packaging as JAR.

I am having dependency for both in web peoject. So I have to use Maven Profile and Overlays such way, that when I will build and package my web project with profile JavaProject1 then web project includes SimpleJavaProject1 in its war and when I said JavaProject2 then it should include SimpleJavaProject2. And it should use Overlays only for specified java project.

Can I use Overlays in Profile?

Please suggest some idea if any...


Solution

  • Got it...referring @Duncan answer I have tried following and its worked. :-)

    Following are my Profiles,

    <profile>
        <id>JavaProject1</id>
        <properties>
            <roject.groupId>mygroupId</project.groupId>
            <roject.artifactId>myartifactId</project.artifactId>
            <roject.version>${myversion}</project.version>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    
    <profile>
        <id>JavaProject2</id>
        <properties>
            <roject.groupId>mygroupId</project.groupId>
            <roject.artifactId>myartifactId</project.artifactId>
            <roject.version>${myversion}</project.version>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    

    And I have added Overlays in war plugin as follows,

    <overlays>
        <overlay>
            <groupId>${project.groupId}</groupId>
            <artifactId>${project.artifactId}</artifactId>
            <type>jar</type>
            <targetPath>WEB-INF/classes</targetPath>
        </overlay>
    </overlays>
    

    It worked successfully. :-)