【问题标题】:Maven generate jar dependencies then warMaven生成jar依赖然后war
【发布时间】:2014-01-03 13:16:53
【问题描述】:

我正在为 Eclipse 使用 m2e Maven 插件。我有 5 个日食项目。一个 Web 应用程序项目,然后是 4 个项目作为我的 Web 应用程序的 jar 依赖项。

我想知道如何在 WAR 项目中使用“mvn clean install”将 jar 包包含在 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>

提前谢谢你。

【问题讨论】:

  • 详情请看我的帖子!

标签: java eclipse maven m2e


【解决方案1】:

@Jigar Joshi 的回答很好,但我觉得你需要一个结构视图,它可以帮助你快速理解我们的意思。

我。创建一个顶级 maven 模块(war 和 jars 的父级) 您已经拥有所需的 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>

二。将您的 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>

三。在所有其他项目中,将父引用放入 poms

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

四。现在你可以进入新创建的父项目内部并从那里运行

mvn clean install

【讨论】:

  • 我有相同的结构但仍然有[ERROR] Non-resolvable parent POM: Failure to find dispatcher:dispatcherParent:pom:4.7 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 7, column 10 -&gt; [Help 2]
  • 中的 ../Dispatcher/pom.xml 解决了它。谢谢。
【解决方案2】:

要么创建一个顶级 maven 模块(war 和 jars 的父级)并执行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 命令行选项也可以建立依赖关系

【讨论】:

  • 也许您的意思不是 parent,而是 reactor 模块/pom? Parent 共享公共插件/依赖项,而 reactor 仅触发 &lt;modules&gt;
  • 是的,创建一个充当战争之父和罐子之父的模块并构建它,如果 OP 想要自定义构建,她/他可以使用绑定在父模块的自定义构建配置文件
  • 我按照 Jigar 和 Festus 的建议尝试了父/模块结构,但现在尝试“mvn clean install”时出现此错误:[INFO] 正在扫描项目... [错误] 构建无法读取 5 个项目 -> [帮助 1] [错误]
  • [ERROR] The project PacificaIntegrateurReferentiel:PacificaIntegrateurReferentiel:4.7 (C:\Users\melbakkali\workspace_kepler\referentiel\pom.xml) has 1 error [ERROR] Non-resolvable parent POM: Failure to find Dispatcher:Dispatcher:pom:4.7 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 17, column 10 -&gt;
  • 查看目录ascii结构和poms,还可以查看如何声明&lt;modules&gt;&lt;parent&gt;
猜你喜欢
  • 1970-01-01
  • 2012-06-07
  • 1970-01-01
  • 1970-01-01
  • 2012-11-01
  • 2014-10-06
  • 1970-01-01
  • 2014-03-02
  • 1970-01-01
相关资源
最近更新 更多