0

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...

milind_db
  • 1,274
  • 5
  • 34
  • 56

2 Answers2

1

I'm not familiar with overlays, but hopefully this approach will work for them too.

Typically one solves this sort of problem by defining a property in your parent POM, based on the profile:

<profiles>
    <profile>
        <id>JavaProject1</id>
        <properties>
          <java.project>SimpleJavaProject1</java.project>
          <java.project.version>1.1</java.project.version>
        </properties>
    </profile>
    <profile>
        <id>JavaProject2</id>
        <properties>
          <java.project>SimpleJavaProject2</java.project>
          <java.project.version>1.2</java.project.version>
        </properties>
    </profile>
</profiles>

Then use this property when you define your dependency (and hopefully your overlays too):

<dependency>
    <groupId>com.foo</groupId>
    <artifactId>${java.project}</artifactId>
    <version>${java.project.version}</version>
</dependency>
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • What if have two profiles, i.e. one for environment e.g. dev or prod and another for above example i.e. javaproject1 or javaproject2. How can I handle this? Can I use overlays in profile? – milind_db Jun 24 '14 at 12:16
  • 1
    @milind You can have more than one profile active at once. So you could have both `dev` and `javaproject2` active. As I mentioned, I don't know much about overlays so can't advise I'm afraid. – Duncan Jones Jun 24 '14 at 12:19
1

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. :-)

milind_db
  • 1,274
  • 5
  • 34
  • 56