Maven and Ant integration

From Kb

Jump to: navigation, search

Contact Article Author | Blog of Article Author | FirstPartners.net Home | LinkedIn profile of Author

See Also

Spring Framework | Appfuse Information | Deploying to Weblogic using Maven | Maven Information

Calling Ant From Maven

<!-- This goes in the root project tag -->
<build>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
 
         <artifactId>maven-antrun-plugin</artifactId>
 
         <executions>
            <execution>
               <phase>compile</phase>
 
               <configuration>
		<!-- Put the Ant Tasks that you wish to call here -->
                  <tasks>
                     <echo>Copy Resources </echo>
 
                     <copy file="${basedir}/source" tofile="${basedir}/target/" overwrite="true" />
                  </tasks>
               </configuration>
 
               <goals>
                  <goal>run</goal>
               </goals>
            </execution>
         </executions>
      </plugin>
   </plugins>
</build>


  • Method 2 : to avoid pollution pom.xml , put the ant tasks in an external build file and use the [Ant Task] within the <tasks> tag instead. E.g the following snippet will call the default task in a build.xml file in the same dir as the pom.xml , all other defaults being passed over.
<tasks>
 <ant/>
</tasks>

Sample Ant Build File

A very basic ant build file to carry out a copy task. Based on Sample Ant Buildfile

<project name="MyProject" default="copy-test-resources" basedir=".">
    <description>
        Copy Spring Resources so that they are available for Unit test
    </description>
 
  <target name="copy-test-resources">
      <!-- Ant Copy Task -->
      <copy todir=".">
			<fileset dir="src/main/webapp/">
				<include name="*.properties" />
			</fileset>
		</copy>
		<copy todir=".">
			<fileset dir="src/main/webapp/WEB-INF">
				<include name="spring*.xml" />
			</fileset>
		</copy>
  </target>
 
 
</project>
Personal tools