gpt4 book ai didi

maven - 将多个 spring web 项目合并为一个可部署的 war

转载 作者:行者123 更新时间:2023-12-04 12:28:36 34 4
gpt4 key购买 nike

请帮助找到将两个或多个 Spring Web 项目合并到单个可部署的 war 文件中的解决方案。我有以下项目

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

到目前为止还不错。但是我有一个新要求,对于不同的客户,我们可以拥有(客户特定功能) salem-web-customer1、 salem-web-customer2 等。
  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

我们需要部署 salem-web 和 salem-web-customer1 为 customer1 和其他客户的一个包裹。

我已经尝试过 提供的解决方案Maven 覆盖 和其他线程没有任何运气。您能否建议正确的配置(如果可能)将两个 Web 项目合并为一个。

最佳答案

有几种可能性,你可以这样做:

有一个父 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>

例如,每个 jar 和 war 项目都有依赖项的项目
<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>

当您构建整个项目时,您将在不同的目标文件夹中拥有所需的所有 war :
./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

关于maven - 将多个 spring web 项目合并为一个可部署的 war ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42802979/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com