对于战争路径,您可以使用内置的 Maven 属性:
${project.build.directory}/${project.build.finalName}.${project.packaging}
您希望将部署路径设置为自定义 Maven 属性。有几种方法可以做到这一点。一种是直接在 pom 中设置,如下所示:
<properties>
<deploy.path>C:/Softwares/apache-tomcat-6.0.33/webapps/Test.war</deploy.path>
</properties>
但是,这仍然是对 pom 中的路径进行硬编码,只是在一个变量中。
另一种方法是使用properties-maven-plugin读取属性文件。这将用户特定的设置排除在 pom 之外,并且您可以将属性文件排除在源代码控制之外。但是,这不是首选的 Maven 做事方式,未来版本可能不再支持此插件。
执行此操作的 Maven 方法是将部署路径存储在 ~/.m2/settings.xml 文件中。此属性将进入配置文件,默认情况下可以处于活动状态。有关说明,请参阅此页面。
设置 deploy.path 变量后,将复制语句更改为如下所示:
<copy file="${project.build.directory}/${project.build.finalName}.${project.packaging}"
tofile="${deploy.path}" />
编辑:
在一个最小的示例项目中,为我设置了以下属性:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<echo message="project.build.directory: ${project.build.directory}"/>
<echo message="project.build.finalName: ${project.build.finalName}"/>
<echo message="project.packaging: ${project.packaging}"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
If those properties aren't set for you, can you post your pom.xml?