gpt4 book ai didi

java - 如何制作Spring Boot多模块项目的单个war文件

转载 作者:行者123 更新时间:2023-11-29 02:58:05 26 4
gpt4 key购买 nike

我的主根 pom 以及 web 模块 pom 和模型模块 pom 在那里所以如何制作单个 war 文件而不是每个模块的多个 war 文件。或者从这些生成的 jars 生成 war 文件和 war 文件包含application.properties 和 WEB-INF 以及 META-INF 文件夹和 lib 文件夹

主 pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>web</module>
<module>model</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.codemaster</groupId>
<artifactId>college-management-system</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>college-management-system</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>13</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>



</project>

网络模块 pom.xml

<?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">
<parent>
<artifactId>college-management-system</artifactId>
<groupId>com.codemaster</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>web</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.codemaster</groupId>
<artifactId>model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

</project>

模型模块pom.xml

<?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">
<parent>
<artifactId>college-management-system</artifactId>
<groupId>com.codemaster</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>model</artifactId>
<packaging>jar</packaging>

</project>

那么如何只制作单个war文件而不是每个模块的多个war文件

最佳答案

你的多模块项目结构和POM应该是这样的

父级 - pom.xml -> 打包 pom

Module1 - pom.xml -> 打包jar

Module2 - pom.xml -> 打包jar

Web - pom.xml -> 打包大战

父 POM

<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>application-base</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<modules>
<module>module1</module>
<module>module2</module>
<module>web</module>
</modules>
<dependencies>
----
</dependencies>
</project>

模块 POM

<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>
<parent>
<groupId>com.example</groupId>
<artifactId>application-base</artifactId>
<version>1.0.0</version>
</parent>
<packaging>jar</packaging>
<artifactId>module</artifactId>
<name>Module</name>
<description>/description>
<dependencies>
------
</dependencies>
</project>

网络 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>
<parent>
<groupId>com.example</groupId>
<artifactId>application-base</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>web</artifactId>
<name>web</name>
<packaging>war</packaging>
<description></description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>module</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
</plugins>
</build>
</project>

关于java - 如何制作Spring Boot多模块项目的单个war文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59476630/

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