【问题标题】:Specify Library Target of Maven指定 Maven 的库目标
【发布时间】:2015-08-18 07:44:30
【问题描述】:

如何告诉 Maven 将依赖项复制到特定位置?

旁白:我在 Eclipse 中有一个 GWT 项目,它也是一个大型项目的 Maven 模块。这个 GWT 项目依赖于一些库,我需要将它们复制到 <project-dir>/war/WEB-INF/lib。我怎样才能告诉 Maven 这样做?


编辑:我找到了一种复制单个依赖项的方法 - 但有没有一种方法可以通过简单的指令复制所有依赖项?

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.10</version>
        <executions>
            <execution>
                <id>copy</id>
                <phase>package</phase>
                <goals>
                    <goal>copy</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>junit</groupId>
                            <artifactId>junit</artifactId>
                            <overWrite>false</overWrite>
                            <outputDirectory>${basedir}/war/WEB-INF/lib</outputDirectory>
                            <destFileName>optional-new-name.jar</destFileName>
                        </artifactItem>
                    </artifactItems>
                    <outputDirectory>${project.build.directory}/wars</outputDirectory>
                    <overWriteReleases>false</overWriteReleases>
                    <overWriteSnapshots>true</overWriteSnapshots>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>  

我也试过这个:

</dependencies>

<build>
    <outputDirectory>${project.basedir}/war/WEB-INF/classes</outputDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <!-- up to <phase>deploy</phase> -->
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.basedir}/war/WEB-INF/lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

</build>

以错误告终:

Artifact 尚未打包。在反应堆工件上使用时,应在打包后执行复制:参见 MDEP-187。

【问题讨论】:

    标签: xml eclipse maven gwt


    【解决方案1】:

    看起来你试图让 Maven 做一些不同于它期望你做的事情(例如,这里使用 war 作为输入和输出文件夹)。根据经验,永远不要试图与 Maven 战斗,你最终会输。遵循(几乎没有记录的)Maven Way™ 或只是使用另一个灵活的工具(例如 Ant+Ivy 或 Gradle)。

    如果您想在 Eclipse 中通过 Google Plugin for Eclipse 使用 GWT 和 Maven,请查看 https://web.archive.org/web/20130619170526/https://developers.google.com/eclipse/docs/faq#gwt_with_mavenhttps://code.google.com/p/google-web-toolkit/wiki/WorkingWithMaven

    要直接回答您的问题,假设有一个带有&lt;packaging&gt;war&lt;/packaging&gt; 的项目,您已经将warSourceDirectory 从其src/main/webapp 默认更改为war,然后尝试war:inplace
    推荐的方法(见上面的链接)是使用war:exploded(或war:war,即简单的mvn package)并使用webappDirectory而不是warSourceDirectory运行GWT DevMode。

    【讨论】:

    • 非常好的答案,尤其是对于刚接触 Maven 的人!很高兴我在开始设置一切,所以我可能会选择另一个系统 - 让我们看看我必须与 Maven 斗争多久。谢谢你的回答!
    • 如果你想在 Maven 中使用 GWT,我建议从我的原型开始:github.com/tbroyer/gwt-maven-archetypes 如果你想了解更多关于 Maven 的设计及其限制的信息,请查看我的博客(其中有很多其他)blog.ltgt.net
    • 哦,我明白了 - Eclipse 中 Maven 模块的项目向导让我可以选择不同的原型,但是我如何安装一个新的?我想我必须阅读更多关于 Maven 的信息。我仍然不确定我是否喜欢它..
    • 好的,我知道这可行,但我不确定如何将这些项目与 Eclipse 集成 ..
    • 我通常从命令行启动我的构建工具(Ant 或 Maven 或 Gradle);我使用的唯一 IDE 集成是工作区/项目的自动配置(然后是特定的编辑器,例如 JSNI 或 UiBinder)。我不会从 Eclipse 中“启动”项目(即使使用 Run as…→ Maven…,部分原因是 Eclipse 硬杀死进程的方式,让分叉进程运行并通过关闭挂钩阻止清理)。
    【解决方案2】:

    dependency:copy-dependencies 应该可以完成这项工作。

    【讨论】:

    • 我已经试过了,但我最终得到一个错误消息“Artifact还没有被打包。当用于reactor artifact时,应该在打包后执行复制”。 .
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 2021-03-13
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    相关资源
    最近更新 更多