eclipsemavenjakarta-eeweblogic

How to choose root-context by maven profile


I am using maven to package an ear-file. I have 2 profiles. 1 profile (aras) is for production. The other profile (aras_nb) is for the nightly build. I want to package 2 different ear-files. Both ear-files should run on the same weblogic. The ear-Files have different Datasources, too. That works already. Now I want to choose the URL by the maven profile. What do I have to do to get this running?

I have a master project, an ear-project, a web-project and an ejb-project.

pom of the master project:

<groupId>xxx.yyy</groupId>
<artifactId>Aras</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Aras</name>

<properties>
    <application.name>Aras</application.name>
    <application.ear.name>Aras-ear</application.ear.name>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <context-root>value</context-root>
</properties>

<modules>
    <module>Aras-ear</module>
    <module>Aras-web</module>
    <module>Aras-ejb</module>
</modules>

<profiles>
    <profile>
        <id>choose_environment</id>
        <build>
            <!-- enable resource filter to set the datasource name -->
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </profile>
    <profile>
        <id>aras</id>
        <properties>
            <datasource.name>ArasDataSource</datasource.name>
            <environment.name>ARAS</environment.name>
            <contextroot.name>/aras</contextroot.name>
        </properties>
    </profile>
    <profile>
        <id>aras_nb</id>
        <properties>
            <datasource.name>ArasNbDataSource</datasource.name>
            <environment.name>ARAS-NB</environment.name>
            <contextroot.name>/aras_nb</contextroot.name>
        </properties>
    </profile>
</profiles>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

In eclipse I execute maven "clean package" with the profiles "choose_environment, aras". When I maven-update the projects, the context-root is automatically set back to "Aras-web".


Solution

  • Found it.

    pom of aras:

    <profiles>
        <profile>
            <id>aras</id>
            <properties>
                <datasource.name>ArasDataSource</datasource.name>
                <environment.name>ARAS</environment.name>
                <rootcontext.name>aras</rootcontext.name>
                <earfile.name>Aras-ear</earfile.name>
            </properties>
        </profile>
        <profile>
            <id>aras_nb</id>
            <properties>
                <datasource.name>ArasNbDataSource</datasource.name>
                <environment.name>ARAS-NB</environment.name>
                <rootcontext.name>aras_nb</rootcontext.name>
                <earfile.name>Aras_nb-ear</earfile.name>
            </properties>
        </profile>
    </profiles>
    

    pom of aras-ear:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <version>6</version>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                    <finalName>${earfile.name}-${project.Version}</finalName>
                    <modules> 
                        <webModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>Aras-web</artifactId>
                            <contextRoot>/${rootcontext.name}</contextRoot>
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>