ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Topping" <topp...@digidemic.com>
Subject Ant Classpath -- Help Requested
Date Mon, 20 Aug 2001 17:43:42 GMT
Greetings and salutations,

I first sent this to the Ant-user list, but got no response so I thought
I would try here.  It is rather technical in nature, so maybe I should
have started here, but I was saving this list for a last resort.

I'm trying to get Ant working with an external taskdef, but without
configuring the CLASSPATH of the Ant itself.  So I've added the
following to my build.xml:

	<property name="enhydra.root" value="C:/eas4/lutris-eas4"/>
	<property name="enhydra.output" value="C:/eas4/lutris-eas4"/>
	<property name="enhydra.liboutput"
value="C:/eas4/lutris-eas4/lib"/>
	<property name="enhydra.jdkdir" value="C:/jdk1.3.1"/>
	<path id="xmlc.classpath">
		<fileset dir="${enhydra.liboutput}">
			<include name="build.jar"/>
			<include name="boot.jar"/>
			<include name="kernel.jar"/>
			<include name="xmlc.jar"/>
			<include name="wireless.jar"/>
			<include name="LutrisWireless.jar"/>
			<include name="dods.jar"/>
			<include name="ctxrmic.jar"/>
		</fileset>
		<fileset dir="${enhydra.jdkdir}/lib">
			<include name="tools.jar"/>
		</fileset>
	</path>
	<taskdef name="xmlc" classname="org.enhydra.ant.taskdefs.Xmlc"
		classpathref="xmlc.classpath"/>

Did I set this up correctly?  I am trying to get the CLASSPATH that is
set up for both Ant (when it executes taskdef
org.enhydra.ant.taskdefs.Xmlc) and org.enhydra.ant.taskdefs.Xmlc itself
(it has a bunch of libraries that it needs to be successful).  What I
get when I run it with 1.3 is:

java.io.IOException: java.lang.NoClassDefFoundError:
org/enhydra/error/ChainedException
        at
org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.ja
va:439)
        at
org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:492)
        at
org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:465)
        at
org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:369)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
        at org.enhydra.xml.xmlc.commands.xmlc.XMLC.<init>(XMLC.java:49)
        at org.enhydra.xml.xmlc.commands.xmlc.XMLC.main(XMLC.java:128)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.enhydra.ant.taskdefs.Xmlc.execute(Xmlc.java:549)
        at org.apache.tools.ant.Target.execute(Target.java:153)
        at org.apache.tools.ant.Project.runTarget(Project.java:898)
        at org.apache.tools.ant.Project.executeTarget(Project.java:536)
        at org.apache.tools.ant.Project.executeTargets(Project.java:510)
        at org.apache.tools.ant.Main.runBuild(Main.java:421)
        at org.apache.tools.ant.Main.main(Main.java:149)
java.lang.reflect.InvocationTargetException:
java.lang.NoClassDefFoundError: org/enhydra/xml/xmlc/XMLCException
        at org.enhydra.xml.xmlc.commands.xmlc.XMLC.<init>(XMLC.java:49)
        at org.enhydra.xml.xmlc.commands.xmlc.XMLC.main(XMLC.java:128)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.enhydra.ant.taskdefs.Xmlc.execute(Xmlc.java:549)
        at org.apache.tools.ant.Target.execute(Target.java:153)
        at org.apache.tools.ant.Project.runTarget(Project.java:898)
        at org.apache.tools.ant.Project.executeTarget(Project.java:536)
        at org.apache.tools.ant.Project.executeTargets(Project.java:510)
        at org.apache.tools.ant.Main.runBuild(Main.java:421)
        at org.apache.tools.ant.Main.main(Main.java:149)

Everything seems to be working fine up to
org.enhydra.ant.taskdefs.Xmlc.execute(Xmlc.java:549) (line 549 is
highlighted):

        } else {
          String [] _args = (String[])args.toArray(new
String[args.size()]);

          // Execute XMLC directly.  This requires that enhydra.jar, or
an equivalent
          // path containing the needed DOM code is on the CLASSPATH of
ANT.
          String xmlcClassName =
"org.enhydra.xml.xmlc.commands.xmlc.XMLC";

          Method      m = null;
          Class       c = null;
          try {
              c = Class.forName(xmlcClassName);
              m = c.getMethod("main", new Class[] { String[].class });

          } catch(Exception e) {
              // Reflection errors.  Class or method does not exist!
              e.printStackTrace();
              throw new BuildException(e);
          }

          if (m != null) {
549->              m.invoke(null,new Object[] { _args });
          }
        }
      } catch(InvocationTargetException ite) {
        ite.printStackTrace();
        throw new BuildException(ite);

Basic reflection code, right?  The class is found and the method call
works.  But the comments at the top of this block state that the
relevant JAR files must be already on the Ant CLASSPATH.  Problem is, I
cannot do that, I am trying to run this build in NetBeans/Forte 3.x and
there is a confirmed problem with the library compatibility between
Enhydra and NB.  I believe I need to use the classpath attribute in the
Antfile taskdef in order to get around this NB library problem.

Moving up the call chain, the source of the real error is in XMLC.java
line 49, and it is failing to instantiate a class that exists in the
same package and jar file as the caller itself!  So somehow it seems
that the CLASSPATH is initially getting set up correctly by the code in
the build.xml, but it is not surviving the reflection call through the
method interface since the first instantiation of another object from
that JAR is failing.  *THIS* is the problem I am trying to solve.  How
can I make the CLASSPATH that is getting set up in the Build.xml
"sticky"??!??!!?

I hope this all makes some semblance of sense to someone that can offer
tips toward a solution.  I've beat on this nonstop for a solid day and
have come up with a little over nothing...



Thanks very kindly for your consideration,


Brian Topping

Mime
View raw message