【问题标题】:Include external eclipse project in maven generated war as jar在 Maven 生成的战争中包含外部 Eclipse 项目作为 jar
【发布时间】:2016-11-09 15:02:08
【问题描述】:

我有一个 Eclipse 项目,它引用了另一个项目。
我已将这个其他项目包含在“属性”->“Java 构建路径”和“属性”->“部署程序集”中,用于在 eclipse 工作区中定义的服务器上进行部署。
此配置包括WEB-INF/lib目录下的外部项目的jar。

现在我想使用(右键单击)“运行方式”->“Maven 安装”命令生成一个战争文件。
我在 pom 中添加了 maven-war-plugin 插件:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <webappDirectory>${project.build.directory}/${project.artifactId}</webappDirectory>
        <warName>${project.artifactId}_${noVer}</warName>
        <archive>
            <addMavenDescriptor>false</addMavenDescriptor>
            <manifest>
                <addClasspath>false</addClasspath>
            </manifest>
            <manifestEntries/>
            <manifestFile/>
        </archive>
    </configuration>
</plugin>

是否可以将其他项目作为 jar(自动)包含在战争中?

谢谢。

编辑

“其他项目”是同一工作区中的 Eclipse 项目。
实际上是一个 maven jar 项目。
如前所述,它包含在原始项目中。
我想知道的是:
有没有办法(插件、指令...)将此 ECLIPSE 项目直接包含在原始项目的 pom 中?

<dependency>
    <groupId>org.myproject</groupId>
    <artifactId>other_eclipse_project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

然后在WEB-INF/lib中找到一个“other_eclipse_project.jar”

【问题讨论】:

    标签: java eclipse maven jar


    【解决方案1】:

    也许您的意思是 Eclipse 能够直接从工作区获取 Maven 依赖项。此功能称为“工作区分辨率”。打开“MyApp”的上下文菜单,在“Maven”中可以激活工作区解析。在 Eclipse Mars 中,默认情况下它是禁用的 (AFAIK)。

    【讨论】:

      【解决方案2】:

      我建议你将“其他项目”的jar文件安装在本地maven仓库中。为此,请使用 maven 安装插件。有一些变体:

      1. 为“其他项目”创建一个pom.xml 并调用mvn install:install-file -Dfile=&lt;path-to-file&gt; -DpomFile=&lt;path-to-pomfile&gt;。在“其他项目”的 POM 中,指定其依赖项。
      2. 指定maven坐标为参数:mvn install:install-file -Dfile=&lt;path-to-file&gt; -DgroupId=&lt;group-id&gt; -DartifactId=&lt;artifact-id&gt; -Dversion=&lt;version&gt; -Dpackaging=jar

      当您选择变体 2 时,您不能(AFAIK)指定“其他项目”的依赖项。

      完成此操作后,您可以在 maven 项目中添加对“其他项目”的依赖项。

      另见Install non-maven artifact in local repository

      【讨论】:

        【解决方案3】:

        Ulrich 的回答是正确的,但它只会将其他项目生成的 jar 添加到您的战争中。如果您的其他项目依赖于其他 jar,则不会包含它们。

        我很想将另一个项目更改为 maven 项目并将其所有依赖项添加到其 pom 中,这样您将获得所有传递依赖项。

        【讨论】:

        • 我同意。当我写下我的答案时,对我来说似乎很清楚只有一个外部库(“其他项目”)不作为 maven 依赖项存在。
        猜你喜欢
        • 1970-01-01
        • 2015-10-02
        • 2017-02-12
        • 1970-01-01
        • 2017-12-19
        • 2014-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多