指定Maven的库目标
如何告诉Maven将依赖关系复制到特定的位置?
How can I tell Maven to copy the dependencies into a specific location?
侧面故事:我在Eclipse中有一个GWT项目,也是一个Maven模块一个更大的项目。这个GWT项目依赖于某些库,我需要将它们复制到< project-dir> / war / WEB-INF / lib
中。如何告诉Maven这样做?
Side story: I am having a GWT project in Eclipse that is also a Maven Module for a larger project. This GWT project has dependencies to some libraries and I need them to be copied into <project-dir>/war/WEB-INF/lib
. How can I tell Maven to do that?
编辑:我找到了一种方式复制一个依赖关系 - 但是有没有办法用一个简单的指令复制所有这些?
Edit: I have found a way to copy a single dependency - but is there a way to copy all of them with a simple instruction?
<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>
结束一个错误说:
神器尚未打包。当在反应堆工件上使用时,应在打包后执行复制:请参阅MDEP-187。
Artifact has not been packaged yet. When used on reactor artifact, copy should be executed after packaging: see MDEP-187.
看起来你试图弯曲Maven做的不同于它期望你做(例如这里使用 war
都作为输入和输出文件夹)。根据经验,永远不要试图与Maven战斗,你最终会失败。遵循(几乎无证的)Maven Way™,或者仅使用另一种更多灵活工具(如Ant + Ivy或Gradle)。
It looks like you're trying to bend Maven to do things differently than what it expects you to do (e.g. here use war
both as input and output folder). As a rule of thumb, never try to fight with Maven, you'll lose eventually. Follow the (almost-undocumented) Maven Way™ or just use another, more flexible tool (such as Ant+Ivy or Gradle).
如果您希望使用Eclipse中的Gaven使用GWT与Google Eclipse插件,那么请查看 https://web.archive.org/web/20130619170526/https://developers.google.com/eclipse/docs/faq#gwt_with_maven 和 https://code.google.com/p/google-web -toolkit / wiki / WorkingWithMaven
If you want to use GWT with Maven from within Eclipse with the Google Plugin for Eclipse, then have a look at https://web.archive.org/web/20130619170526/https://developers.google.com/eclipse/docs/faq#gwt_with_maven and https://code.google.com/p/google-web-toolkit/wiki/WorkingWithMaven
要直接回答您的问题,假设项目为< packaging> war< / packaging>
将您的 warSourceDirectory
从 src / main / webapp
的默认值更改为 war
,然后尝试 war:inplace
。
推荐的方法(见上面的链接)是使用 战争:爆炸
(或 war:战争
,即一个简单的 mvn软件包
),并运行GWT DevMode使用 webappDirectory
,而不是 warSourceDirectory
。
To answer your question directly, assuming a project with <packaging>war</packaging>
where you'd have changed the warSourceDirectory
from its src/main/webapp
default to war
, then try war:inplace
.
The recommended approach though (see links above) is to use war:exploded
(or war:war
, i.e. a simple mvn package
) and run GWT DevMode using the webappDirectory
, not warSourceDirectory
.