Maven生成jar依赖,然后再战

编程入门 行业动态 更新时间:2024-10-10 14:30:12
本文介绍了Maven生成jar依赖,然后再战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用m2e Maven Plugin for Eclipse。我有5个eclipse项目。一个Web应用程序项目,然后4个项目作为我的Web应用程序的jars依赖项。

我想知道如何在将jar包包含在WAR中之前使用mvn

这是我的pom.xml:

< project xmlns =maven.apache/POM/4.0.0xmlns:xsi =www.w3/2001/XMLSchema-instance xsi :schemaLocation =maven.apache/POM/4.0.0 maven.apache/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> <依赖关系> <依赖关系> < groupId> referentiel< / groupId> < artifactId> referentiel< / artifactId> < version> 4.7< / version> < / dependency> <依赖关系> < groupId> mailTemplates< / groupId> < artifactId> mailTemplates< / artifactId> < version> 0.0.1-SNAPSHOT< / version> < / dependency> <依赖关系> < groupId> qualityTool< / groupId> < artifactId> qualityTool< / artifactId> < version> 0.0.1-SNAPSHOT< / version> < / dependency> <依赖关系> < groupId> tools< / groupId> < artifactId> tools< / artifactId> < version> 0.0.1-SNAPSHOT< / version> < / dependency> ... .. 。 < / dependencies> < / project>

提前谢谢。

解决方案

@Jigar Joshi的答案是好的,但我需要一个结构视图,可以帮助您快速了解我们的意思。

我。创建一个顶级的maven模块(战争和罐子的父母)你已经拥有了你需要的5个模块。现在创建一个新的Maven项目作为父项,它只能包含一个pom.xml文件。

父项目pom

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

II。把你的罐子项目首先作为模块,最后是战争项目。如果您在jar项目中有其他依赖项,那么您也可以尝试订购它们。

父项目pom

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

III。在所有其他项目中,将父参照放入poms

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

IV。现在你可以去新创建的父项目里面,从那里运行

mvn clean install

I'm using m2e Maven Plugin for Eclipse. I'm having 5 eclipse projects. A web application project and then 4 projects as jars dependencies for my web application.

I would like to know how can I package jars before including them in the WAR using "mvn clean install" on war project.

Here's my pom.xml:

<project xmlns="maven.apache/POM/4.0.0" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="maven.apache/POM/4.0.0 maven.apache/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>

Thank you in advance.

解决方案

The answer of @Jigar Joshi is good but i thing you need a view of structure which can help you to understand quickly what we mean.

I. Create a top level maven module (parent of war and jars) You habe already the 5 moduls that you need. Now create a new Maven project as parent which must contain only a pom.xml file.

parent project pom

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

II. Put your jar projects first as modul and at the end the war project. If you have another dependencies in the jar projects you may also try to order them consequently.

parent project pom

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

III. in all other project put the parent reference into the poms

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

IV. Now you can go to inside the new created parent project and run from there

mvn clean install

更多推荐

Maven生成jar依赖,然后再战

本文发布于:2023-11-27 18:37:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639143.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:再战   Maven   jar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!