简体   繁体   English

Maven生成jar依赖,然后战争

[英]Maven generate jar dependencies then war

I'm using m2e Maven Plugin for Eclipse. 我正在使用m2e Maven Plugin for Eclipse。 I'm having 5 eclipse projects. 我有5个日食项目。 A web application project and then 4 projects as jars dependencies for my web application. 一个Web应用程序项目,然后将4个项目作为我的Web应用程序的jar依赖项。

I would like to know how can I package jars before including them in the WAR using "mvn clean install" on war project. 我想知道如何在战争项目中使用“mvn clean install”将jar包装到WAR之前将其打包。

Here's my pom.xml: 这是我的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. 先感谢您。

Either create a top level maven module (parent of war and jars) and execute mvn clean install 创建一个顶级maven模块(战争和jar的父)并执行mvn clean install

---pom.xml
   |
   |dispatcher---pom.xml (war)
   |qualityTool----pom.xml (jar)
   |mailTemplates----pom.xml (jar)
   |referentiel----pom.xml (jar)
   |tools----pom.xml (jar)

or use --also-make command line option to make dependencies as well 或者使用--also-make命令行选项来创建依赖项

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. @Jigar Joshi的答案很好,但我需要一个结构视图,可以帮助你快速理解我们的意思。

I. Create a top level maven module (parent of war and jars) You habe already the 5 moduls that you need. I.创建一个顶级maven模块(战争和罐子的父母)你已经是你需要的5个模块。 Now create a new Maven project as parent which must contain only a pom.xml file. 现在创建一个新的Maven项目作为父项,它必须只包含一个pom.xml文件。

parent project pom 父项目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. II。 Put your jar projects first as modul and at the end the war project. 首先将你的jar项目作为modul,最后是war项目。 If you have another dependencies in the jar projects you may also try to order them consequently. 如果您在jar项目中有另一个依赖项,那么您也可以尝试对它们进行排序。

parent project pom 父项目pom

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

III. III。 in all other project put the parent reference into the poms 在所有其他项目中将父引用放入poms中

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

IV. IV。 Now you can go to inside the new created parent project and run from there 现在,您可以进入新创建的父项目内部并从那里运行

mvn clean install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM