Community
Participate
Working Groups
I have done a "Restore Defaults" in my preferences/external tools/ant/classpath tab, so it has the plugins ant.jar, optional.jar xmlParserAPIs.jar, xercesImpl.jar and the jdk's tools.jar. When I execute my build.xml, target build_xmlctask, I get the following error: D:\myApp\taskdefs\XMLCTask.java:10: cannot resolve symbol symbol : class DirectoryScanner location: package ant import org.apache.tools.ant.DirectoryScanner; If I run Ant with -debug, here is what it says my classpath was for the javac invocation: XMLCTask.java added as D:\myapp\taskdefs\XMLCTask.class doesn't exist. Compiling 1 source file to D:\myapp\taskdefs Using modern compiler Compilation args: -d D:\myapp\taskdefs -classpath D:\myapp\taskdefs;D:\myapp\lib\xmlc.jar;D:\eclipse\startup.jar -sourcepath D:\FlightDeck\taskdefs -g:none File to be compiled: D:\myapp\taskdefs\XMLCTask.java I don't understand why the classpath I set for running Ant from inside Eclipse isn't being picked up as part of the classpath being used by the javac ant task. Here is my build.xml file: <project name="myapp" default="package" basedir="."> <target name="setProps" unless="setProps" description="setup the properties."> <property name="tomcat.dir" value="D:/jakarta-tomcat-3.2.1" /> <property name="db2.dir" value="lib" /> </target> <target name="init" depends="setProps"> <tstamp /> <property name="app.name" value="myapp" /> <property name="taskdefs.dir" value="taskdefs" /> <property name="src.dir" value="src" /> <property name="lib.dir" value="lib" /> <property name="build.dir" value="build" /> <property name="dist.dir" value="dist" /> <property name="java.source.dir" value="${src.dir}/java" /> <property name="xmlc.source.dir" value="${src.dir}/html" /> </target> <target name="clean" depends="init"> <delete includeEmptyDirs="true" quiet="yes"> <fileset dir="${build.dir}" /> <fileset dir="${dist.dir}" /> <fileset dir="taskdefs" includes="*.class" /> </delete> </target> <target name="prepare" depends="init" description="prepare the output directories"> <mkdir dir="${build.dir}" /> <mkdir dir="${dist.dir}" /> </target> <target name="build_xmlctaskdef" depends="init"> <javac srcdir="${taskdefs.dir}" destdir="${taskdefs.dir}" includes="*.java"> <classpath> <pathelement location="${lib.dir}/xmlc.jar" /> </classpath> </javac> </target> <target name="xmlc" depends="build_xmlctaskdef, prepare"> <property name="build.sysclasspath" value="ignore" /> <patternset id="xmlc.sources"> <include name="${xmlc.source.dir}/*.html" /> </patternset> <taskdef name="xmlctask" classname="XMLCTask"> <classpath> <pathelement location="${lib.dir}/xmlc.jar" /> <pathelement location="taskdefs" /> </classpath> </taskdef> <xmlctask classpath="${lib.dir}/xmlc.jar" destdir="${build.dir}" package="com.myco.web.ui.html" srcdir="${xmlc.source.dir}" excludesfile="${xmlc.source.dir}/xmlc.ignore" /> </target> <target name="compile" depends="xmlc"> <javac srcdir="${java.source.dir}" destdir="${build.dir}" debug="yes"> <include name="**/*.java" /> <classpath> <fileset dir="${lib.dir}"> <include name="jaxp.jar" /> </fileset> <fileset dir="${lib.dir}"> <include name="**/*.jar" /> </fileset> </classpath> </javac> </target> <target name="package" depends="compile"> <mkdir dir="${dist.dir}" /> <jar jarfile="${dist.dir}/${app.name}.jar" basedir="${build.dir}" includes="com/**" /> </target> <target name="all" depends="clean, package" description="perform build" /> <target name="run" depends="package"> <java fork="yes" classname="org.apache.tomcat.startup.Tomcat"> <arg line="-config ${tomcat.dir}\conf\server.xml -home ${tomcat.dir}" /> <!-- <jvmarg value="-server"/> --> <jvmarg value="-ms64M" /> <jvmarg value="-mx128M" /> <classpath> <fileset dir="${lib.dir}"> <include name="*.jar" /> </fileset> <fileset dir="${tomcat.dir}/lib"> <include name="*.jar" /> </fileset> <pathelement path="${db2.dir}/java/db2java.zip"/> <pathelement path="${db2.dir}/bin" /> <pathelement path="${dist.dir}/${app.name}.jar" /> </classpath> </java> </target> <target name="runprofile" depends="package"> <java fork="yes" classname="org.apache.tomcat.startup.Tomcat"> <arg line="-config ${tomcat.dir}\conf\server.xml -home ${tomcat.dir}" /> <jvmarg value="-server" /> <jvmarg value="-ms64M" /> <jvmarg value="-mx128M" /> <jvmarg value="- Xrunhprof:heap=all,cpu=samples,thread=y,depth=10,cutoff=0,format=a" /> <!--<jvmarg value="- Xrunhprof:cpu=samples,thread=y,depth=10,cutoff=0,format=a"/> --> <classpath> <fileset dir="${lib.dir}"> <include name="**/*.jar" /> </fileset> <fileset dir="${tomcat.dir}/lib"> <include name="**/*.jar" /> </fileset> <pathelement path="${db2.dir}/java/db2java.zip" /> <pathelement path="${db2.dir}/bin" /> <pathelement path="${dist.dir}/${app.name}.jar" /> </classpath> </java> </target> <target name="rundebug" depends="package"> <java fork="yes" classname="org.apache.tomcat.startup.Tomcat"> <arg line="-config ${tomcat.dir}\conf\server.xml -home ${tomcat.dir}" /> <jvmarg value="-server" /> <jvmarg value="-ms64M" /> <jvmarg value="-mx128M" /> <jvmarg value="-Xdebug" /> <jvmarg value="- Xrunjdwp:transport=dt_shmem,address=flightdeck,server=y,suspend=n" /> <classpath> <fileset dir="${lib.dir}"> <include name="**/*.jar" /> </fileset> <fileset dir="${tomcat.dir}/lib"> <include name="**/*.jar" /> </fileset> <pathelement path="${db2.dir}/java/db2java.zip" /> <pathelement path="${db2.dir}/bin" /> <pathelement path="${dist.dir}/${app.name}.jar" /> </classpath> </java> </target> <target name="stop"> <java fork="yes" classname="org.apache.tomcat.startup.Tomcat"> <arg line="-config ${tomcat.dir}\conf\server.xml -home ${tomcat.dir} - stop" /> <classpath> <fileset dir="${tomcat.dir}/lib"> <include name="**/*.jar" /> </fileset> </classpath> </java> </target> </project>
I have the same issue.
(and I'm running Integration build 20020621)
I'm still using F3 (20020612)
Does it work outside Eclipse?
Yes it does, here's the debug output from running it from Ant outside of Eclipse: ... ... ... init: Setting project property: DSTAMP -> 20020624 Setting project property: TSTAMP -> 2008 Setting project property: TODAY -> June 24 2002 Setting project property: app.name -> myapp Setting project property: taskdefs.dir -> taskdefs Setting project property: src.dir -> src Setting project property: lib.dir -> lib Setting project property: build.dir -> build Setting project property: dist.dir -> dist Setting project property: java.source.dir -> src/java Setting project property: xmlc.source.dir -> src/html build_xmlctaskdef: FileSet: Setup file scanner in dir D:\myapp\taskdefs with patternSet{ includes: [*.java] excludes: [] } [javac] XMLCTask.java added as D:\myapp\taskdefs\XMLCTask.class doesn't exist. [javac] Compiling 1 source file to D:\myapp\taskdefs [javac] Using modern compiler [javac] Compilation args: -d D:\myapp\taskdefs -classpath D:\myapp\taskdefs;D:\myapp\lib\xmlc.jar;D:\jakarta-ant- 1.4.1\lib\jaxp.jar;D:\jakarta-ant-1.4.1\lib\jakarta-ant-1.4.1- optional.jar;D:\jakarta-ant-1.4.1\lib\crimson.jar;D:\jakarta-ant-1.4.1 \lib\ant.jar;C:\jdk1.3.1_03\lib\tools.jar -sourcepath D:\myapp\taskdefs -g:none [javac] File to be compiled: D:\FlightDeck\taskdefs\XMLCTask.java
My build runs properly outside of eclipse as well. For me, it as to do with adding ant.jar to the classpath. Apparently, eclipse's built-in ant external tool doesn't add ant.jar to the classpath (even if org.apache.ant is in the build path)? mike
I'm not sure how the javac task computes its classpath. I know that there is a parameter in javac (includeAntRuntime) that specifies whether to include the Ant JARs to the compile path and its default is yes. I haven't investigated to see how they compute the classpath depending on this parameter. Since 2.0 is practically frozen we will only look at the problem later. For now you can use Michael's workaround (adding ant.jar to the classpath manually). Defer.
It is my understanding Ant takes into account the following in setting up the classpath: - property build.sysclasspath (allowed values only/ignore/last/first) and the javac task's properties: includeAntRuntime includeJavaRuntime Also, some good pertinent information can be had from: http://jakarta.apache.org/ant/faq.html#delegating-classloader and http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ClassLoader.html
Reopening for investigation.
The root of the problem here is that "command-line" Ant adds all .jar files from ANT_HOME/lib to CLASSPATH. Within Eclipse there is no ANT_HOME, outside of Eclipse there is always an ANT_HOME.
Understood. Correct me if I'm wrong, but doesn't ant (on the commandline) pick up the CLASSPATH set in the environment? Translated to ant (within eclipse), shouldn't the classpath for the project be used and passed to ant (which is necessary if the project contains its own ant tasks)?
I had not thought of adding the project classpath...I have prototyped adding the ant classpath as specified on the ant preference page. Does this seem reasonable?
To fully describe what I have found: The system classpath is stored as a public static variable on the org.apache.tools.ant.types.Path class. This variable is initialized with the String found using System.getProperty("java.class.path"). Within Eclipse, Ant is currently only available within the same VM that Eclipse is launched (see bug 24129). This means that java.class.path is set to the classpath that was set to launch Eclipse. Obviously this differs from the classpath that is used to launch Ant from the commandline. For the javac task (where includeAntRuntime is true by default), this results in decidedly different jars being added to the javac classpath. The proposed fix will set the Path.systemClasspath to the Ant classpath as specified in the Ant preference page. Setting the Ant classpath on a per project basis is covered in bug 15405. Once this was implemented we could supplement the classpath with the project settings.
Created FrameworkTests#testIncludeAntRuntime.
Fixed in InternalAntRunner. Please verify (Jared)
Verified code.