gpt4 book ai didi

java - Maven 生成 jar 依赖然后 war

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

我正在为 Eclipse 使用 m2e Maven 插件。我有 5 个 eclipse 项目。一个 Web 应用程序项目,然后是 4 个项目作为我的 Web 应用程序的 jars 依赖项。

我想知道如何在 war 项目上使用“mvn clean install”将 jar 包含在 WAR 中之前打包它们。

这是我的 pom.xml:

<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>dispatcher</groupId>
<artifactId>dispatcher</artifactId>
<version>4.0</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>referentiel</groupId>
<artifactId>referentiel</artifactId>
<version>4.7</version>
</dependency>
<dependency>
<groupId>mailTemplates</groupId>
<artifactId>mailTemplates</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>qualityTool</groupId>
<artifactId>qualityTool</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>tools</groupId>
<artifactId>tools</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
...
..
.
</dependencies>
</project>

提前谢谢你。

最佳答案

@Jigar Joshi 的回答很好,但我认为您需要一个结构 View ,它可以帮助您快速理解我们的意思。

我。创建顶级 Maven 模块(war 和 jars 的父模块)您已经拥有所需的 5 个模块。现在创建一个新的 Maven 项目作为父项目,它必须只包含一个 pom.xml 文件。

父项目pom

 <project...>               
<groupId>groupId</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Define parent pom </name>
<!-- modul -->
<project>

二。将您的 jar 项目作为模块放在首位,最后是 war 项目。如果您在 jar 项目中有其他依赖项,您也可以尝试对它们进行排序。

父项目pom

 <modules>
<module>referentiel</module> <!-- jar -->
<module>mailTemplates</module> <!-- jar -->
<module>qualityTool</module> <!-- jar -->
<module>tools</module> <!-- jar -->
<module>dispatcher</module> <!-- war-->
</modules>

三。在所有其他项目中将父引用放入 poms

   <parent>
<groupId>groupId</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>

四。现在您可以进入新创建的父项目并从那里运行

mvn clean install

关于java - Maven 生成 jar 依赖然后 war,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20606001/

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