我有一些配置文件和各种文档,我想使用Maven2将它们从开发环境复制到dev-server目录。奇怪的是,Maven在这项任务上似乎并不强大。
以下是一些选项:
简单地使用Maven中的复制任务
< =“src /游戏/资源/文件副本配置。财产“tofile = ${项目配置}-配置服务器。财产" - >
Use the Ant plugin to execute copy from Ant.
Construct an artifact of type zip, alongside the "main" artifact of the POM which is usually of type jar, then unpack that artifact from the repository into the target directory.
maven-resources plugin, as mentioned below.
Maven Assembly plugin -- but this seems to require a lot of manual definitions, when I want to do things simply and "conventionally."
This page even shows how to build a plugin to do copying!
maven-upload plugin, as mentioned below.
maven-dependency-plugin with copy, as mentioned below.
所有这些似乎都是不必要的特别任务:Maven应该擅长于毫不费力地完成这些标准任务。
任何建议吗?
上面的蚂蚁解决方案是最容易配置的,但我有幸使用了Atlassian的maven-upload-plugin。我找不到好的文档,下面是我如何使用它:
<build>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-upload-plugin</artifactId>
<version>1.1</version>
<configuration>
<resourceSrc>
${project.build.directory}/${project.build.finalName}.${project.packaging}
</resourceSrc>
<resourceDest>${jboss.deployDir}</resourceDest>
<serverId>${jboss.host}</serverId>
<url>${jboss.deployUrl}</url>
</configuration>
</plugin>
</build>
像“${jboss.”上面引用的Host}定义在我的~/.m2/settings.xml中,并使用maven配置文件激活。这个解决方案并不局限于JBoss,这只是我给变量命名的方式。我有开发,测试和现场的资料。因此,要在测试环境中上传我的耳朵到jboss实例,我将执行:
mvn upload:upload -P test
下面是settings.xml的一个片段:
<server>
<id>localhost</id>
<username>username</username>
<password>{Pz+6YRsDJ8dUJD7XE8=} an encrypted password. Supported since maven 2.1</password>
</server>
...
<profiles>
<profile>
<id>dev</id>
<properties>
<jboss.host>localhost</jboss.host>
<jboss.deployDir>/opt/jboss/server/default/deploy/</jboss.deployDir>
<jboss.deployUrl>scp://root@localhost</jboss.deployUrl>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<jboss.host>testserver</jboss.host>
...
注:
有这个插件的Atlassian maven repo在这里:https://maven.atlassian.com/public/
我建议下载源代码,并查看其中的文档,以了解插件提供的所有功能。
`