Rob
Rob

Reputation: 4224

Ant/Build a JAR : Build failed, Reference task.path not found

I'm working on a project with a build.xml to generate a JAR file. When I try to build it I get this error:

Buildfile: D:\xxxxx\trunk\project-java\build.xml

BUILD FAILED D:\xxxxxtrunk\project-java\build.xml:25: Reference task.path not found.

Total time: 140 milliseconds

Build.xml with the line where it crashes.

<?xml version="1.0"?>
<project name="xxxxx" default="prepare-release" basedir=".">

<property name="project.dir" value="."/>
<property file="${project.dir}/build.properties"/>
<property file="${project.dir}/svn.properties"/>

<property name="dist.dir" value="${project.dir}/dist"/>

<property name="build.dir" value="${project.dir}/build"/>
<property name="src.dir" value="${dist.dir}/${dist.type}/src"/>
<property name="release.dir" value="${project.dir}/release"/>



<!-- load svn tasks -->
// Pb on this line
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" 
     classpathref="task.path" />

What can it be? Thanks for your help.

Upvotes: 1

Views: 2851

Answers (2)

kjhughes
kjhughes

Reputation: 111491

  1. Search your entire build.xml, the transitive closure of included files, and all super projects for the string "task.path".
  2. If missing or not of the following form, add or correct the form. Be sure you're not trying to identify it in some manner other than an @id attribute setting.

    <path id="task.path">
       ...
    </path>
    
  3. If found but in a super project (which calls the current project via ant or antcall tasks), set the inheritrefs attribute to true to pass along the definition.

  4. If found but in a parallel task that also defines the same @id value, the last task to finish will override the other's reference. Consider cleaning things up to avoid ambiguity.

See also: Ant objects and references: what is the scope of a reference's ID?

Upvotes: 1

David W.
David W.

Reputation: 107030

BUILD FAILED D:\xxxxxtrunk\project-java\build.xml:25: Reference task.path not found.

Well, where is the classpath task.path defined in your build.xml file?

When you define a task via <taskdef>, you need to do several things:

  • You need to specify the jar file where the task exists.
  • You need to specify the class that contains the task, and how to find it in the jar. This can be done in one of two ways:
    • You say the class is in com.foo.bar.mytask, and then give it a name.
    • You can specify a resource in the jar (either a properties file or an XML file) which pretty much says what class is associated with each name (which is what resource="org/tigris/subversion/svnant/svnantlib.xml" is doing.
  • Finally, you need to specify how to find that jar file.

That last one you're missing. You specified a reference to a classpath called task.path, but didn't actually define that classpath.

There are several things you can do:

  • You can put the jar into the $ANT_HOME/lib directory. When you define a task via <taskdef/>, Ant automatically looks there. I'm not fond of this because it means that you build doesn't work on other users' machines because they may not have that jar installed.

  • You can define a classpath to find it.

This is my preference, and here's how I usually do it.

<taskdef resource="org/tigris/subversion/svnant/svnantlib.xml">
    <classpath>
       <fileset dir="${basedir}/antlib/svnant}"/>
    </classpath>
</taskpath>

In your project, create a directory called ${basedir}/antlib/svnant and put all five jars that came with this SVNAnt task in that directory. This way, all of the jars you need for your optional build tasks are now inside your project. If someone checks out your project from the version control system, they automatically get the needed task jars.

I put all of my optional ant task jars in that ${basedir}/antlib directory, and put each in their own directory in that directory.

Remember I said one of the things you need is to specify the class that contains the task?. Here's what that org/tigris/subversion/svnant/svnantlib.xml file you specified looks like in svnant.jar:

<?xml version="1.0"?>
<antlib>
  <!-- Tasks -->
  <taskdef name="svn"
    classname="org.tigris.subversion.svnant.SvnTask" />

  <!-- Types -->
  <typedef name="svnFileSet"
    classname="org.tigris.subversion.svnant.types.SvnFileSet" />

  <!-- Selectors -->
  <typedef name="svnNormal"
    classname="org.tigris.subversion.svnant.selectors.Normal" />
  <typedef name="svnAdded"
    classname="org.tigris.subversion.svnant.selectors.Added" />
  <typedef name="svnReplaced"
    classname="org.tigris.subversion.svnant.selectors.Replaced" />
  <typedef name="svnModified"
    classname="org.tigris.subversion.svnant.selectors.Modified" />
  <typedef name="svnConflicted"
    classname="org.tigris.subversion.svnant.selectors.Conflicted" />
  <typedef name="svnIgnored"
    classname="org.tigris.subversion.svnant.selectors.Ignored" />
  <typedef name="svnUnversioned"
    classname="org.tigris.subversion.svnant.selectors.Unversioned" />
  <typedef name="svnLocked"
    classname="org.tigris.subversion.svnant.selectors.Locked" />
  <typedef name="svnMissing"
    classname="org.tigris.subversion.svnant.selectors.Missing" />
  <typedef name="svnDeleted"
    classname="org.tigris.subversion.svnant.selectors.Deleted" />

  <!-- Conditions -->
  <typedef name="svnExists"
    classname="org.tigris.subversion.svnant.conditions.Exists" />

</antlib>

It's just a map of task names to classes inside the jar.

Upvotes: 1

Related Questions