2013-12-16 78 views
1

我使用的是用于Eclipse的m2e Maven插件。我有5个eclipse项目。一个Web应用程序项目,然后4个项目作为我的Web应用程序的罐子依赖项。Maven生成jar依赖项然后战

我想知道在使用战争项目中的“mvn clean install”将WAR包括到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> 

预先感谢您。

+0

请看我的文章了解更多详情! –

回答

2

@Jigar乔希的答案是:好,但我需要一个结构视图,可以帮助你快速理解我们的意思。

I.创建一个顶级的maven模块(战争和罐子的父亲) 你已经是你需要的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> 

II。首先将你的jar项目作为模块,然后放在战争项目的最后。如果你在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 
+0

我有相同的结构,但仍然有 '[[ ERROR]无法解析的父POM:找不到调度程序:http://repo.maven.apache.org/maven2中的dispatcherParent:pom:4.7缓存在本地存储库中,直到中央更新间隔后才会重新解析分辨率已经过去或者更新被强制并且'parent.relativePath'指向错误的本地POM @第7行,第10列 - > [Help 2]' – Emowpy

+0

../ Di spatcher/pom.xml解决了它。谢谢。 – Emowpy

2

可以创建一个顶级行家模块(战争和罐子的母公司)和执行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) 

或使用--also-make命令行选项,以使依赖以及

+0

也许你的意思不是* parent *,而是* reactor * module/pom?父共享公共插件/依赖项,而reactor只是触发''。 –

+0

是创建一个模块作为战争和瓶子的父亲和建设它,如果OP要定制构建他/他可以去定制构建配置文件绑定在父模块 –

+0

我尝试父/模块结构作为Jigar和Festus建议,但我'mvn clean install'时出现此错误: [INFO]正在扫描项目... [错误]构建无法读取5个项目 - > [Help 1] [ERROR] – Emowpy