且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Maven生成jar依赖,然后再战

更新时间:2022-10-14 23:35:22

@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&gt

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