Merge multiple spring web projects into one deployable war

Please help to find solution to merge two or more spring web projects into single deployable war file. I have following projects

myproject 
  a. core 
    - src
    - pom.xml
        - packaging = jar
  b. dao 
    - src
    - pom.xml
        - packaging = jar
        - dependency on core project
  c. service
    - src
    - pom.xml 
        - packaging = jar
        - dependency on core and dao projects
  d. salem-web
    - src
    - pom.xml
        - packaging = war
        - dependency on core, dao and service projects

So far it is good. But I have a new requirement, for different customers we can have (customer specific features) salem-web-customer1, salem-web-customer2 etc..

  e. service-customer1
    - src
    - pom.xml 
        - packaging = jar
        - dependency on core and dao projects

  f. salem-web-customer1
    - src
    - pom.xml
        - packaging = war
        - dependency on core, dao and service-customer1 projects

We need to deploy salem-web & salem-web-customer1 as one package for customer1 and so on for other customers.

I already tried solutions provided by maven overlays and other threads without any luck. Could you please suggest the correct configuration (if possible) to merge two web projects into one.


There are a few possibilities, you could do it like this:

Have a parent pom :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.greg</groupId>
    <artifactId>salem</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>core</module>
        <module>dao</module>
        <module>service</module>
        <module>service-customer1</module>
        <module>salem-web</module>
        <module>salem-web-customer1</module>
    </modules>

</project>

Have projects with dependencies for each jar and war project, for example

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.greg</groupId>
  <artifactId>service-customer1</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>service-customer1</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.greg</groupId>
      <artifactId>core</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>com.greg</groupId>
      <artifactId>dao</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

And for a war project:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.greg</groupId>
        <artifactId>salem</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>salem-web-customer1</artifactId>
    <packaging>war</packaging>

    <name>salem-web-customer1 Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <dependency>
            <groupId>com.greg</groupId>
            <artifactId>core</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.greg</groupId>
            <artifactId>dao</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.greg</groupId>
            <artifactId>service-customer1</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>salem-web-customer1</finalName>
    </build>

</project>

When you build the whole project you will have all the wars you need in the different target folders:

./dao/target/dao-1.0-SNAPSHOT.jar
./salem-web/target/salam-web.war
./salem-web-customer1/target/salem-web-customer1/WEB-INF/lib/core-1.0-SNAPSHOT.jar
./salem-web-customer1/target/salem-web-customer1/WEB-INF/lib/dao-1.0-SNAPSHOT.jar
./salem-web-customer1/target/salem-web-customer1/WEB-INF/lib/service-customer1-1.0-SNAPSHOT.jar
./salem-web-customer1/target/salem-web-customer1.war
./service/target/service-1.0-SNAPSHOT.jar
./service-customer1/target/service-customer1-1.0-SNAPSHOT.jar
链接地址: http://www.djcxy.com/p/95602.html

上一篇: 无服务器Web服务器?

下一篇: 将多个弹簧网站项目合并为一个可展开的战争