Bug 20857 - Problems with Ant classpath not being picked up
Summary: Problems with Ant classpath not being picked up
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Ant (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: 2.1 M3   Edit
Assignee: Jared Burns CLA
QA Contact:
URL:
Whiteboard:
Keywords: core
Depends on:
Blocks:
 
Reported: 2002-06-22 14:14 EDT by Jon Christiansen CLA
Modified: 2002-11-25 22:04 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Christiansen CLA 2002-06-22 14:14:53 EDT
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>
Comment 1 Michael R. Head CLA 2002-06-22 16:23:34 EDT
I have the same issue.
Comment 2 Michael R. Head CLA 2002-06-22 16:25:13 EDT
(and I'm running Integration build 20020621)
Comment 3 Jon Christiansen CLA 2002-06-24 00:57:56 EDT
I'm still using F3 (20020612)
Comment 4 Rodrigo Peretti CLA 2002-06-24 09:46:19 EDT
Does it work outside Eclipse?
Comment 5 Jon Christiansen CLA 2002-06-24 20:08:32 EDT
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
Comment 6 Michael R. Head CLA 2002-06-24 20:25:09 EDT
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
Comment 7 Rodrigo Peretti CLA 2002-06-25 15:54:10 EDT
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.
Comment 8 Jon Christiansen CLA 2002-06-25 17:28:17 EDT
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

Comment 9 DJ Houghton CLA 2002-09-10 16:58:04 EDT
Reopening for investigation.
Comment 10 Darin Swanson CLA 2002-10-30 12:00:15 EST
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.
Comment 11 Michael R. Head CLA 2002-10-30 16:55:51 EST
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)?
Comment 12 Darin Swanson CLA 2002-10-30 17:13:59 EST
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?
Comment 13 Darin Swanson CLA 2002-10-30 19:22:00 EST
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.
Comment 14 Darin Swanson CLA 2002-10-31 11:12:40 EST
Created FrameworkTests#testIncludeAntRuntime.
Comment 15 Darin Swanson CLA 2002-10-31 11:22:22 EST
Fixed in InternalAntRunner.
Please verify (Jared)
Comment 16 Jared Burns CLA 2002-11-25 22:04:35 EST
Verified code.