I am trying to set the ant build file to user Maven dependencies and I am getting error as "Failed to create task or type urn:maven-artifact-ant:localRepository
package uk.co.rrv;
import org.joda.time.DateTime;
public class Main {
public static void main(String[] args) {
DateTime dateTime = new DateTime();
System.out.println("DateTime = " + dateTime);
System.out.println("Plus 1 hour is " + dateTime.plusHours(1));
System.out.println("Plus 10 minutes is " + dateTime.plusMinutes(10));
System.out.println("Plus 60 seconds is " + dateTime.plusSeconds(60));
}
}
Here is my Build xml file
<project name="TestBuild" basedir="." default="main" xmlns:artifact="antlib:maven.artifact.ant">
<path id="maven-ant-tasks.classpath" path="Lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="uk.co.rrv.Main"/>
<target name="clean">
<echo>Initializing ....</echo>
<delete dir="${build.dir}"/>
</target>
<target name="compile" depends="mvn-init">
<echo>Compling ....</echo>
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="maven-ant-tasks.classpath"/>
<copy todir="${classes.dir}">
<fileset dir="${log.dir}" excludes="**/*.java"/>
</copy>
</target>
<target name="jar" depends="compile">
<echo>Building Jar ....</echo>
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<echo>Execution ....</echo>
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>
</java>
</target>
<target name="mvn-init" unless="compile.classpath" xmlns:artifact="urn:maven-artifact-ant">
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant"
classpath="Lib/maven-ant-tasks-2.1.3 .jar"/>
<condition property="maven.repo.local" value="${maven.repo.local}" else="${user.home}/.m2/repository">
<isset property="maven.repo.local"/>
</condition>
<echo>maven.repo.local=${maven.repo.local}</echo>
<artifact:localRepository id="local.repository" path="${maven.repo.local}"/>
<artifact:pom file="pom.xml" id="maven.project"/>
<artifact:dependencies pathId="compile.classpath" filesetId="compile.fileset" useScope="compile">
<pom refid="maven.project"/>
<localRepository refid="local.repository"/>
</artifact:dependencies>
<artifact:dependencies pathId="test.classpath" filesetId="test.fileset" useScope="test">
<pom refid="maven.project"/>
<localRepository refid="local.repository"/>
</artifact:dependencies>
<artifact:dependencies pathId="runtime.classpath" filesetId="runtime.fileset" useScope="runtime">
<pom refid="maven.project"/>
<localRepository refid="local.repository"/>
</artifact:dependencies>
</target>
<target name="main" depends="clean,run"/>
</project>
Here is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>seamjpa</groupId>
<artifactId>seamjpa</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>seam-jpa</name>
<repositories>
<repository>
<id>repository.jboss.org</id>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<build>
<finalName>${project.name}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>true</debug>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<seam.version>2.2.0.GA</seam.version>
<jsf.version>1.2_12</jsf.version>
<richfaces.version>3.3.1.GA</richfaces.version>
<slf4j.version>1.4.2</slf4j.version>
</properties>
</project>
After fixing the references to maven-ant-tasks jar,
- <path id="maven-ant-tasks.classpath" path="Lib/maven-ant-tasks-2.1.3.jar" />
+ <path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.1.3.jar" />
- <javac ... classpathref="maven-ant-tasks.classpath"/>
+ <javac ... classpathref="compile.classpath"/>
- <path refid="classpath"/>
+ <path refid="runtime.classpath"/>
- classpath="Lib/maven-ant-tasks-2.1.3 .jar"/>
+ classpath="lib/maven-ant-tasks-2.1.3.jar"/>
See also usage examples in the docs including bootstrapping via ant that probably has useful examples.