You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Richard Keene <ri...@asgnetwork.com> on 2003/01/28 21:06:07 UTC

Summary - Class Not Found

Here is a summary of how to solve the class not found error in the 
torque-build.xml file.
Maybe someone in the Troque group could do a writeup and include it in 
the distibution.
If Who Ever Is In Charge emails me I'll do the writeup in HTML if you'd 
like.

The original problem:
I downloaded Torque latest version (torque-3.0-rc2.jar etc.).  Modified 
the config files
for a simple test database with MySQL.
When I ran the ant build script, torque-build.xml in NetBeans it failed 
with...

WEB-INF/build-torque.xml [75] taskdef class 
org.apache.torque.task.TorqueDataModelTask cannot be found

I then studied the build file alot and it setsup the classpath and such 
correctly.  I then tried many variations
of the classpath for the taskdef tag.  What taskdef does in Ant is add a 
new task or tag that you can use.
The lines
  <taskdef
    name="torque-data-model"
    classpathref="torque-classpath"
    classname="org.apache.torque.task.TorqueDataModelTask"/>

Make it so that you can do things like

    <torque-data-model
      controlTemplate="${torque.template.sqlDbInit}"
      outputDirectory="${torque.sql.dir}"
      outputFile="create-db.sql"
      targetDatabase="${torque.database}"
      templatePath="${torque.templatePath}"
      useClasspath="${torque.useClasspath}">
      <fileset dir="${torque.schema.dir}"
        includes="${torque.schema.create-db.includes}"
        excludes="${torque.schema.create-db.excludes}"
      />
    </torque-data-model>

And the org.apache.torque.task.TorqueDataModelTask class is the custom 
code to implement the
new tag.

I then thought it was the classloader in Ant which is mentioned in the 
change notes for the latest Ant as
a problem.  In fact Ant does have a problem where the classpath or 
classref is ignored for taskdef
tags and that is the problem here.
Finally I tried the -v flag on Ant and got the deeper exception which is 
realy...

java.lang.NoClassDefFoundError: org/apache/velocity/texen/ant/TexenTask

Unfortunately this is not output normaly.  So, what this realy means is 
another .jar file is missing.

Solution:
Since ant ignores the classpath and claspathdef for taskdef's you need 
to setup the classpath externaly.
(Actally to be correct, Ant does not ignore the classpath or 
classpathdef, the classloader in some
 of the included libraries does.)
Any one of the following Fixes should work, though I've only tested the 
first one.

Fix 1: Copy all the .jar files from the Torque/lib directory to the 
Ant/lib directory.  On my machine
this is C:/torque/lib and C:/ant/lib respectively.  
This fix is what I did, and is quick and dirty.  It is not a realy good 
idea if you are doing lots of projects
that use different revisions of libraries.

Fix 2: Set the CLASSPATH to include all the libraries in the torque/lib 
directory.
This is a better, but tedious fix.  It does let you use a script to set 
the CLASSPATH
for various projects and avoid the problems of Fix #1

Fix 3: Change the torque-build.xml extensively so it uses the java tag 
to call out to the
builder engine classes and remove the taskdef entirely.  This is a 
difficult solution but is probably
what the Torque owners should do.

Fix 4: Don't use ant at all.  Use Maven or Krysalis Centipede instead. 
 I'm not sure what that would involve.

---

Richard Keene
richard@asgnetworks.com