Maven生成jar依赖,然后再战 [英] Maven generate jar dependencies then war

查看:117
本文介绍了Maven生成jar依赖,然后再战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



这是我的pom.xml:

 < project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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>
<依赖关系>
<依赖关系>
< 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="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>

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依赖,然后再战的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆