2013-05-28 94 views
5

我希望能够将配置值从maven传递给ant。如果这是有道理的。将参数从'maven'传递给ant任务

我希望能够将变量传递给这个任务:

比方说,我定义一个变量$ {someArg}我希望能够通过“someArg”的行家脚本并最终构建。 xml ant脚本。

这里是我的定义:

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.7</version> 
    <executions> 
     <execution> 
      <id>gen</id> 
      <phase>generate-resources</phase> 
      <configuration> 
       <target name="main"> 
        <script language="javascript" manager="javax" 
        src="${project.basedir}/src/scripts/myfile.js"/> 
       </target> 
      </configuration> 
      <goals> 
    ${someArg} (how to pass someArg) 
       <goal>run</goal> 
      </goals> 
     </execution> 
... 

然后这里是build.xml文件的一部分:

<?xml version="1.0" ?> <project name="deployment" default="deploy"> 
    <property file="build.properties" /> 
    <target> 
    <echo message="${someArg}" /> 
    </target> 
</project> 

我想传递到build.xml

回答

4

有一个示例在:http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html

在您的配置中pom.xml:

<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> 
      <property name="compile_classpath" refid="maven.compile.classpath"/> 
      <property name="runtime_classpath" refid="maven.runtime.classpath"/> 
      <property name="test_classpath" refid="maven.test.classpath"/> 
      <property name="plugin_classpath" refid="maven.plugin.classpath"/> 

      <echo message="compile classpath: ${compile_classpath}"/> 
      <echo message="runtime classpath: ${runtime_classpath}"/> 
      <echo message="test classpath: ${test_classpath}"/> 
      <echo message="plugin classpath: ${plugin_classpath}"/> 
      </target> 
     </configuration> 
     <goals> 
      <goal>run</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 

Maven的文档说,你可以把在目标标签东西,所以你应该能够使用$ {属性名}的目标使用Maven属性。

+0

这将工作,所以只需复制/添加您需要的属性。 –