Anjan
Anjan

Reputation: 2970

Compiling a build.xml file using Ant

I recently installed Ant 1.8.4 and JasperReports 4.6.0 on my Ubuntu machine.

The following environmental variables were set on my account:

PATH=$PATH:/opt/ant/bin

export PATH

export ANT_HOME=/opt/ant

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64

When I try to run a demo build file in the JasperReports demo samples directory using the command ant I get the following error:

Buildfile: build.xml

BUILD FAILED
/opt/jasperreports-4.6.0/demo/samples/antcompile/build.xml:3: The following
 error occurred while executing this line:
jar:file:/opt/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37: Problem: failed to create task or type componentdef
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

Any help in solving this problem will be super helpful.

The snippet of build.xml file:

<project name="antcompile" default="test" basedir=".">

    <description>Shows how multiple JRXML files can be compiled in batch mode using ANT.</description>

    <path id="classpath">
        <pathelement location="../../../build/classes"/>
        <fileset dir="../../../lib">
            <include name="**/*.jar"/>
        </fileset>
    </path>

    <path id="runClasspath">
        <path refid="classpath"/>
        <pathelement location="../../fonts"/>
        <pathelement location="./build/classes"/>
    </path>

    <taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask"> 
        <classpath refid="classpath"/>
    </taskdef>

    <target name="javac" description="Compiles the Java source files used in the report designs.">
        <mkdir dir="./build/classes"/> 
        <javac srcdir="./src" destdir="./build/classes" debug="true" optimize="false" deprecation="false"/>
    </target> 

    <target name="compile1" description="Compiles report designs specified using the &quot;srcdir&quot; in the &lt;jrc&gt; tag."> <!-- 27 row # -->
        <mkdir dir="./build/reports"/> 
        <jrc 
                srcdir="./reports"
                destdir="./build/reports"
                tempdir="./build/reports"
                keepjava="true"
                xmlvalidation="true">
            <classpath refid="runClasspath"/>
            <include name="**/*.jrxml"/>
        </jrc>
    </target> 

Upvotes: 2

Views: 11549

Answers (3)

David W.
David W.

Reputation: 107040

You're going have to help us out a bit here...

Are you building JasperReports-4.6.0? Or, are you using JasperReports as part of your build.xml? Is this a test build.xml demoing JasperReports?

The error says Check that any custom tasks/types have been declared, so what is the Ant task in line #37? Is there a in the build.xml? Does it have a classpath defined? If you have a taskdef, please let us see what it is, and what the custom task is.

I'm downloading iReport to see if I can figure out what you're doing, but it's taking 15 minutes. I bet you're supposed to put some jar into $ANT_HOME/lib. Maybe that JasperReports or iReport jarfile.

As soon as I can download iReport and see what you're talking about, I'll update my answer.

Meanwhile, include the relevant code around line #35 in your build.xml and the taskdef task in your build.xml.


Finished downloading iReport and there is no build.xml file in it. You're going to have to post your code, so we can look at it.

Again, my assumption is that there's some jar file that they assumed you'd stick in /opt/ant/lib and didn't.

Upvotes: 0

Anjan
Anjan

Reputation: 2970

I made it work by changing the following element in my CLASSPATH, /opt/jasperreports-4.6.0/lib/ant-1.7.1.jar to /opt/ant/lib/ant.jar. Thanks to Alex for posting the helpful links! Anjan

Upvotes: 2

Alex K
Alex K

Reputation: 22857

This Ant script is using custom task jrc.

As you can see from the snippet below (this is build.xml file from the jasperreports-4.6.0/demo/samples/antcompile folder), this task's definition refers the classpath from the same build file.

<path id="classpath">
    <pathelement location="../../../build/classes"/>
    <fileset dir="../../../lib">
        <include name="**/*.jar"/>
    </fileset>
</path>

...

<taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask"> 
    <classpath refid="classpath"/>
</taskdef>

You should check the ../../../build/classes folder (in JasperReports package's folder structure which contains samples) - the net.sf.jasperreports.ant.JRAntCompileTask class must be there.

In other words you should put this class (or jasperreports-4.6.0.jar) to the classpath (path id="classpath").


Another probable source of your problem is the version of Ant package.

You can read about Project#createTask complains it wouldn't find task componentdef issue on Ant's bugtracker and project.createTask() not working with ant-1.8.2 post.

Upvotes: 2

Related Questions