ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Cross <nick.cr...@prismtechnologies.com>
Subject Javac and classpath
Date Wed, 27 Feb 2002 17:51:39 GMT


Hi,

I originally posted this to the user list but in hindsight it is
probably more of a developer question.
Ok, hopefully this will make sense :-) 

The sun javac compiler states that if the '-d' flag is used the
directory is not added to the classpath. The ant javac task makes no
mention of whether this happens when specifying a destdir so I assumed
that it didn't and wrote my XML as follows:

      <javac srcdir="${JAVA.ROOT_DIR}" destdir="${JAVA.CLASS_DIR}"
debug="${JAVA.DEBUG}">
         <include name="${JAVA.COMPILE_TARGET}/*.java"/>
         <classpath>
            <pathelement path="${JAVA.AUX_DIR}"/>
            <pathelement path="${JAVA.GENCLASS_DIR}"/>
            <pathelement path="${JAVA.CLASS_DIR}"/>
            <pathelement path="${java.class.path}"/>
            <fileset dir="${JAVA.JARS_DIR}">
               <include name="**/*.jar"/>
            </fileset>
         </classpath>
      </javac>

This done manually on the command line works fine and produces a clean
build. 
The problem was that the classpath produced by the ant task is not as I
have specified above. It appears that
org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter
automatically adds the dest dir to the classpath. While this is no bad
thing I think it might be better if it was added as follows:

diff -w ~/DefaultCompilerAdapter.java.orig ~/DefaultCompilerAdapter.java
149,155d148
<         // add dest dir to classpath so that previously compiled and
<         // untouched classes are on classpath
<
<         if (destDir != null) {
<             classpath.setLocation(destDir);
<         }
<
170a164,170
>         // add dest dir to classpath so that previously compiled and
>         // untouched classes are on classpath
>
>         if (destDir != null) {
>             classpath.setLocation(destDir);
>         }
>
[diff was with rev. 1.20 ]

This allows the build file writer to exactly specify the classpath. If
the build file writer hasn't specified a classpath the destdir still
gets added as before. 


Thanks very much,

Nick

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message