简体   繁体   中英

Multi module project to deliver two different wars

I am working on a multi module Spring MVC project in which one module has to deliver a war with all dependencies and other has to deliver a war with few dependencies excluded. Is this possible? If yes how can I achieve this? The project details are as below:

The structure is:

Parent pom:
<modules>
  <web-war-with-all-dependencies>
  <web-ear-without-dependencies>  --> Only to pack the war into an ear.
</modules>

A shared library is created in Websphere and all dependencies are added there. So, < web-ear-without-dependencies > will be deployed there. < web-war-with-all-dependencies > will be used to build a docker tomcat image and hosted in a diff environment. My project has to support both environments. Hence the weird requirement.

Using Maven profiles and by adding some dependencies only in some profile or setting them with scope: provided:

https://www.baeldung.com/maven-profiles

Example:

<profiles>
    <profile>
        <id>dev</id>
        <dependencies>
            <dependency>
                <groupId>org.testcontainers</groupId>
                <artifactId>testcontainers</artifactId>
                <version>${testcontainers.version}</version>
            </dependency>
            <dependency>
                <groupId>org.testcontainers</groupId>
                <artifactId>postgresql</artifactId>
                <version>${testcontainers.version}</version>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>prod</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <dependencies>
            <!-- my own library in my private repository which acts like a mock of testcontainers project. Don't ask :-) -->
            <dependency>
                <groupId>cz.jiripinkas</groupId>
                <artifactId>fake-testcontainers</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </profile>
</profiles>

And then you build your project using:

mvn clean install -P dev

This will put inside WAR testcontainers libraries

or:

mvn clean install -P prod

This will put inside WAR fake-testcontainer library

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM