0

I am implementing maven wrapper to ant builds. And the ant command used to build the project is as follows

ant -v -f build.xml -Darch=linux-java7 -Dconfig=/work/build.config -Doutput=/work/bldout/

Now i have to execute the above command through maven . I tried to implement this using "I want to execute shell commands from maven's pom.xml" and "http://sanchitbahal.wordpress.com/2011/09/19/maven-exec-plugin-vs-maven-antrun-plugin-for-running-command-line-tool/"

The sample code i tried inside my pom.xml is as follows :

<plugin>
      <artifactId>exec-maven-plugin</artifactId>
      <groupId>org.codehaus.mojo</groupId>
      <executions>
             <execution>
             <id>execute-shell</id>
              <phase>compile</phase>
              <goals>
                      <goal>exec</goal>
              </goals>
              <configuration>
                      <executable>test.sh</executable>
                      <arguments>
                            <argument>ARG1</argument>
                            <argument>ARG2</argument>
                      </arguments>
             </configuration>
             </execution>
     </executions>
</plugin>

But i am not able to figure out how to pass named parameter such as "-Darch=linux-java7" as arguement to build.xml

Also used maven-antrun plugin to invoke build.xml as follows :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>

     <executions>
       <execution>
          <id>run-target</id>
          <phase>install</phase>
              <configuration>
                 <target>
                    <ant antfile="build.xml" target="all" />
                 </target>
              </configuration>
          <goals>
             <goal>run</goal>
          </goals>
      </execution>

But here also i am unable to figure out how to pass parameter such as "-Darch=linux-java7" as arguement to build.xml

What i know is that i can put the command in a shell script(in a .sh file) and call the shell script using maven-exec-plugin , but wanted to know if it is possible to do without doing so .

Community
  • 1
  • 1

1 Answers1

0

Use antrun, it has less external dependencies (like ant executable on path etc.)

Ant tasks executed by antrun plugin inherit all properties defined inside the properties section of your pom.

So you simple need to include:

<properties>
  <arch>linux-java7</arch>
  ...
</properties>

inside your pom to make it work.

blackbuild
  • 5,026
  • 1
  • 23
  • 35
  • ok , will try adding them in properties tag , also do you know how can i pass -v and -f ant options through pom ? Are those options really necessary when ant is executed through antrun plugin? – user2323134 Apr 02 '14 at 05:22
  • `-f build.xml` is uncessary even while calling from the command line, since the default is `build.xml`. `-v` gives verbose output. There is IMHO no readily available option to do that with antrun (except turning verbose on for the whole maven job using `-X`, do you really need `verbose` output? The idea of verbose is to log extra (debug) information in case something goes wrong, this should not be the default. – blackbuild Apr 02 '14 at 07:58
  • ok , have to speak about it with my teammates , this is the first time i am using ant , better i have to go through ant first . Thanks – user2323134 Apr 02 '14 at 08:38