2013-05-28 85 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

這將工作,所以只需複製/添加您需要的屬性。 –