It's not a secret anymore!*
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant error on trying to run an taskdef Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant error on trying to run an taskdef" Watch "Ant error on trying to run an taskdef" New topic
Author

Ant error on trying to run an taskdef

Jochen Maes
Greenhorn

Joined: Dec 03, 2002
Posts: 20
HI all,

I'm trying to get hyperjaxb working and can't get the ant files working. I'm sure something is wrong with my setup (almost cannot be anything else).

I have an test.xml file (build file) and it has 2 tasks one with a taskdef and one without. (same actions). But when i run the taskdef one i get following error (xml file attached)

SeJo@versake article41 $ ant -f test.xml -d -v
Apache Ant version 1.6.2 compiled on August 17 2004
Apache Ant version 1.6.2 compiled on August 17 2004
Buildfile: test.xml
Detected Java version: 1.4 in: /opt/sun-jdk-1.4.2.05/jre
Detected OS: Linux
parsing buildfile /home/SeJo/workspace/project/test.xml with URI = file:///home/SeJo/workspace/project/test.xml
Project base dir set to: /home/SeJo/workspace/project
Build sequence for target `generate.sources' is [generate.sources]
Complete build sequence is [generate.sources, ]

generate.sources:

BUILD FAILED
/home/SeJo/workspace/project/test.xml:14: taskdef A class needed by class com.sun.tools.xjc.XJCTask cannot be found: org/apache/tools/ant/Task
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:487)
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:183)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
at org.apache.tools.ant.Main.runBuild(Main.java:673)
at org.apache.tools.ant.Main.startAnt(Main.java:188)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
Caused by: java.lang.NoClassDefFoundError: org/apache/tools/ant/Task
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:282)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:282)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java:1180)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:956
)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:457)
... 11 more
--- Nested Exception ---
java.lang.NoClassDefFoundError: org/apache/tools/ant/Task
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:282)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:282)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java:1180)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:956)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:457)
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:183)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
at org.apache.tools.ant.Main.runBuild(Main.java:673)
at org.apache.tools.ant.Main.startAnt(Main.java:188)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)

Total time: 2 seconds




test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="art41" default="generate.sources" basedir=".">
<path id="classpath">
<fileset dir="/opt/jars">
<include name="ant.jar"/>
<include name="hyperjaxb.jar"/>
<include name="jaxb-xjc.jar"/>
<include name="xsdlib.jar"/>
<include name="xercesImpl.jar"/>
<include name="sax.jar"/>
</fileset>
</path>
<target name="generate.sources">
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask"></taskdef>
<mkdir dir="blah.blah"/>
<xjc schema="xml_schema_project.xsd" target="blah.blah" classpathref="classpath.lib">
<arg line="-Xhibernate-xdoclets"/>
<classpath>
<pathelement location="." />
<pathelement location="/opt/jars/ant.jar" />
<pathelement location="/opt/jars/hyperjaxb.jar" />
<pathelement location="/opt/jars/jaxb-xjc.jar" />
<pathelement location="/opt/jars/xsdlib.jar" />
<pathelement location="/opt/jars/xercesImpl.jar" />
<pathelement location="/opt/jars/sax.jar" />
</classpath>
</xjc>
<!-- this one does work if i leave the XHibernation-xdoclets argument out
<java classname="com.sun.tools.xjc.Driver">
<arg line="-dtd"/>
<arg file="xml_schema_project.dtd"/>
<arg line="-xjs"/>
<arg file="xml_schema_project.xjs"/>
<arg line="-Xhibernate-xdoclets"/>
<classpath>
<pathelement location="." />
<pathelement location="/opt/jars/ant.jar" />
<pathelement location="/opt/jars/hyperjaxb.jar" />
<pathelement location="/opt/jars/jaxb-xjc.jar" />
<pathelement location="/opt/jars/xsdlib.jar" />
<pathelement location="/opt/jars/dom4j.jar" />
<pathelement location="/opt/jars/sax.jar" />
<pathelement location="/opt/jars/xercesImpl.jar" />
</classpath>
</java>-->
</target>
</project>
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Looks like the taskdef task is not able to find some class as reported by the exception.



taskdef task allows you to specify the classpath from where the specified class can be loaded.



Try specifying that and see if it works.
Jochen Maes
Greenhorn

Joined: Dec 03, 2002
Posts: 20
solved it, it's a bug in the sun jdk.

IT works perfectly with the ibm jdk...

weird...
David Melkumyan
Greenhorn

Joined: Sep 21, 2004
Posts: 1
Hi,

I`m also trying to execute HyperJAXB with "Simple" example. I can`t understand what is wrong.

I get following error:
".. taskdef A class needed by class xdoclet.modules.hibernate.HibernateDocletTask cannot be found: org/apache/tools/ant/Task"

// ----------------- log file

test.all:
test:
init:

clean:
[delete] Deleting directory H:\Install\Java Tools\HyperJAXB\tests\simple\generated.sources
[delete] Deleting directory H:\Install\Java Tools\HyperJAXB\tests\simple\classes
[delete] Deleting directory H:\Install\Java Tools\HyperJAXB\tests\simple\lib

generate.sources:
[mkdir] Created dir: H:\Install\Java Tools\HyperJAXB\tests\simple\generated.sources
[xjc] Consider using <depends>/<produces> so that XJC won't do unnecessary compilation
[xjc] Compiling file:/H:/Install/Java Tools/HyperJAXB/tests/simple/schema/schema.xsd
[xjc] (addon.ClassNameResolver 73 ) Classname [test.ElementType] resolved to suffix [ElementType].
[xjc] (addon.ClassNameResolver 73 ) Classname [test.EntryType] resolved to suffix [EntryType].
[xjc] (addon.ClassNameResolver 73 ) Classname [test.ObjectFactory] resolved to suffix [ObjectFactory].
[xjc] (addon.ClassNameResolver 73 ) Classname [test.Root] resolved to suffix [Root].
[xjc] (addon.ClassNameResolver 73 ) Classname [test.RootType] resolved to suffix [RootType].
[xjc] (addon.ClassNameResolver 73 ) Classname [test.RootType.Element1] resolved to suffix [Element1].
[xjc] (addon.ClassNameResolver 73 ) Classname [test.RootType.Element2] resolved to suffix [Element2].
[xjc] (addon.HibernateXDocletAddOn 26 ) Field [Ignored] is annotated to be ignored.
[xjc] Writing output to H:\Install\Java Tools\HyperJAXB\tests\simple\generated.sources

compile:
[mkdir] Created dir: H:\Install\Java Tools\HyperJAXB\tests\simple\classes
[javac] Compiling 39 source files to H:\Install\Java Tools\HyperJAXB\tests\simple\classes
[copy] Copying 2 files to H:\Install\Java Tools\HyperJAXB\tests\simple\classes

jar:
[mkdir] Created dir: H:\Install\Java Tools\HyperJAXB\tests\simple\lib
[jar] Building jar: H:\Install\Java Tools\HyperJAXB\tests\simple\lib\test.jar

generate.hibernate.mapping:

BUILD FAILED
H:\Install\Java Tools\HyperJAXB\tests\build.xml:5: The following error occurred while executing this line:
H:\Install\Java Tools\HyperJAXB\tests\build.xml:29: The following error occurred while executing this line:
H:\Install\Java Tools\HyperJAXB\tests\test.build.xml:233: taskdef A class needed by class xdoclet.modules.hibernate.HibernateDocletTask cannot be found: org/apache/tools/ant/Task

Total time: 1 minute 51 seconds

------- Ant diagnostics report -------
Apache Ant version 1.6.2 compiled on July 16 2004

-------------------------------------------
Implementation Version (JDK1.2+ only)
-------------------------------------------
core tasks : 1.6.2
optional tasks : 1.6.2

-------------------------------------------
ANT_HOME/lib jar listing
-------------------------------------------
ant.home: C:\jwsdp-1.4\ant
...

-------------------------------------------
Tasks availability
-------------------------------------------
image : Missing dependency com.sun.media.jai.codec.FileSeekableStream
sshexec : Missing dependency com.jcraft.jsch.UserInfo
scp : Missing dependency com.jcraft.jsch.UserInfo
cvsversion : Not Available
jdepend : Missing dependency jdepend.xmlui.JDepend
junit : Missing dependency junit.framework.Test

-------------------------------------------
org.apache.env.Which diagnostics
-------------------------------------------
Not available.
Download it at http://xml.apache.org/commons/

-------------------------------------------
XML Parser information
-------------------------------------------
XML Parser : org.apache.xerces.jaxp.SAXParserImpl
XML Parser Location: C:\J2SDK\lib\ext\xerces-J_1.4.0.jar

-------------------------------------------
System properties
-------------------------------------------
java.runtime.name : Java(TM) 2 Runtime Environment, Standard Edition
sun.boot.library.path : C:\J2SDK\bin
java.vm.version : 1.4.2_04-b05
ant.library.dir : C:\jwsdp-1.4\ant\lib
java.vm.vendor : Sun Microsystems Inc.
java.vendor.url : http://java.sun.com/
path.separator : ;
java.vm.name : Java HotSpot(TM) Client VM
file.encoding.pkg : sun.io
user.country : US
sun.os.patch.level : Service Pack 1
java.vm.specification.name : Java Virtual Machine Specification
user.dir : H:\Install\Java Tools\HyperJAXB\tests
java.runtime.version : 1.4.2_04-b05
java.awt.graphicsenv : sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs : C:\J2SDK\lib\endorsed
os.arch : x86
java.io.tmpdir : C:\DOCUME~1\mdavid\LOCALS~1\Temp\
line.separator :

java.vm.specification.vendor : Sun Microsystems Inc.
user.variant :
os.name : Windows XP
ant.home : C:\jwsdp-1.4\ant
sun.java2d.fontpath :
java.library.path : C:\J2SDK\bin;.;C:\WINDOWS\System32;C:\WINDOWS;C:\Program Files\SSH SECURE SHELL;C:\WINDOWS\System32\Perl\bin;C:\WINDOWS\System32\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\OPENAFS\Client\Program;C:\Program Files\OPENAFS\Common;C:\VXIpnp\WinNT\Bin;C:\Program Files\National Instruments\LabVIEW 6\cintools;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;%JAVA_PATH%;%JAVA_PATH%\bin;%JAVA_PATH%\lib;%JAVA_PATH%\jre;%JAVA_PATH%\jre\bin;%JAVA_PATH%\jre\lib;C:\jwsdp-1.4\jwsdp-shared\bin;C:\jwsdp-1.4\jwsdp-shared\lib;C:\jwsdp-1.4\ant;C:\jwsdp-1.4\ant\bin;C:\jwsdp-1.4\ant\lib;C:\jwsdp-1.4\jaxb\bin;C:\jwsdp-1.4\jaxb\lib;C:\jwsdp-1.4\jaxp\bin;C:\jwsdp-1.4\jaxp\lib;C:\jwsdp-1.4\jaxp\lib\endorsed;H:\Install\Java Tools\HyperJAXB\lib\xdoclet;C:\Program Files\Far
java.specification.name : Java Platform API Specification
java.class.version : 48.0
java.util.prefs.PreferencesFactory : java.util.prefs.WindowsPreferencesFactory
os.version : 5.1
user.home : C:\Documents and Settings\mdavid
java.specification.version : 1.4
java.class.path : C:\jwsdp-1.4\ant\lib\ant-launcher.jar;H:\Install\Java Tools\HyperJAXB\tests\.\;C:\jwsdp-1.4\ant\lib\ant-antlr.jar;C:\jwsdp-1.4\ant\lib\ant-apache-bcel.jar;C:\jwsdp-1.4\ant\lib\ant-apache-bsf.jar;C:\jwsdp-1.4\ant\lib\ant-apache-log4j.jar;C:\jwsdp-1.4\ant\lib\ant-apache-oro.jar;C:\jwsdp-1.4\ant\lib\ant-apache-regexp.jar;C:\jwsdp-1.4\ant\lib\ant-apache-resolver.jar;C:\jwsdp-1.4\ant\lib\ant-commons-logging.jar;C:\jwsdp-1.4\ant\lib\ant-commons-net.jar;C:\jwsdp-1.4\ant\lib\ant-icontract.jar;C:\jwsdp-1.4\ant\lib\ant-jai.jar;C:\jwsdp-1.4\ant\lib\ant-javama il.jar;C:\jwsdp-1.4\ant\lib\ant-jdepend.jar;C:\jwsdp-1.4\ant\lib\ant-jmf.jar;C:\jwsdp-1.4\ant\lib\ant-jsch.jar;C:\jwsdp-1.4\ant\lib\ant-junit.jar;C:\jwsdp-1.4\ant\lib\ant-launcher.jar;C:\jwsdp-1.4\ant\lib\ant-netrexx.jar;C:\jwsdp-1.4\ant\lib\ant-nodeps.jar;C:\jwsdp-1.4\ant\lib\ant-starteam.jar;C:\jwsdp-1.4\ant\lib\ant-stylebook.jar;C:\jwsdp-1.4\ant\lib\ant-swing.jar;C:\jwsdp-1.4\ant\lib\ant-trax.jar;C:\jwsdp-1.4\ant\lib\ant-vaj.jar;C:\jwsdp-1.4\ant\lib\ant-weblogic.jar;C:\jwsdp-1.4\ant\lib\ant-x alan1.jar;C:\jwsdp-1.4\ant\lib\ant-xslp.jar;C:\jwsdp-1.4\ant\lib\ant.jar;C:\jwsdp-1.4\ant\lib\xalan.jar;C:\jwsdp-1.4\ant\lib\xml-apis.jar;C:\jwsdp-1.4\ant\lib\;C:\jwsdp-1.4\ant\lib\ant-antlr.jar;C:\jwsdp-1.4\ant\lib\ant-apache-bcel.jar;C:\jwsdp-1.4\ant\lib\ant-apache-bsf.jar;C:\jwsdp-1.4\ant\lib\ant-apache-log4j.jar;C:\jwsdp-1.4\ant\lib\ant-apache-oro.jar;C:\jwsdp-1.4\ant\lib\ant-apache-regexp.jar;C:\jwsdp-1.4\ant\lib\ant-apache-resolver.jar;C:\jwsdp-1.4\ant\lib\ant-commons-logging.jar;C:\jwsdp- 1.4\ant\lib\ant-commons-net.jar;C:\jwsdp-1.4\ant\lib\ant-icontract.jar;C:\jwsdp-1.4\ant\lib\ant-jai.jar;C:\jwsdp-1.4\ant\lib\ant-javamail.jar;C:\jwsdp-1.4\ant\lib\ant-jdepend.jar;C:\jwsdp-1.4\ant\lib\ant-jmf.jar;C:\jwsdp-1.4\ant\lib\ant-jsch.jar;C:\jwsdp-1.4\ant\lib\ant-junit.jar;C:\jwsdp-1.4\ant\lib\ant-launcher.jar;C:\jwsdp-1.4\ant\lib\ant-netrexx.jar;C:\jwsdp-1.4\ant\lib\ant-nodeps.jar;C:\jwsdp-1.4\ant\lib\ant-starteam.jar;C:\jwsdp-1.4\ant\lib\ant-stylebook.jar;C:\jwsdp-1.4\ant\lib\ant-swing. jar;C:\jwsdp-1.4\ant\lib\ant-trax.jar;C:\jwsdp-1.4\ant\lib\ant-vaj.jar;C:\jwsdp-1.4\ant\lib\ant-weblogic.jar;C:\jwsdp-1.4\ant\lib\ant-xalan1.jar;C:\jwsdp-1.4\ant\lib\ant-xslp.jar;C:\jwsdp-1.4\ant\lib\ant.jar;C:\jwsdp-1.4\ant\lib\xalan.jar;C:\jwsdp-1.4\ant\lib\xml-apis.jar;C:\J2SDK\lib\tools.jar
user.name : mdavid
java.vm.specification.version : 1.0
java.home : C:\J2SDK
sun.arch.data.model : 32
user.language : en
java.specification.vendor : Sun Microsystems Inc.
awt.toolkit : sun.awt.windows.WToolkit
java.vm.info : mixed mode
java.version : 1.4.2_04
java.ext.dirs : C:\J2SDK\lib\ext
sun.boot.class.path : C:\J2SDK\lib\rt.jar;C:\J2SDK\lib\i18n.jar;C:\J2SDK\lib\sunrsasign.jar;C:\J2SDK\lib\jsse.jar;C:\J2SDK\lib\jce.jar;C:\J2SDK\lib\charsets.jar;C:\J2SDK\classes
java.vendor : Sun Microsystems Inc.
file.separator : \
java.vendor.url.bug : http://java.sun.com/cgi-bin/bugreport.cgi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant error on trying to run an taskdef
 
Similar Threads
Ant build in Beginning Hibernate
NoClassDefFoundError
ant build error
Lomboz problem generating EJB classes
Odd exception with Axis 1.4 and ant taskdef