My configuration: Ant of 4/18/00 2:53 PM (most recent .tar.gz), on NT 4 SP 6 with JDK1.2.2.

I'm having an issue with the destination directory for .class files in Ant builds. My goal is to have the .class file live in the same directory as the .java file.

In my build.xml I say

  <javac
                srcdir="${src.java.dir}/com/databottling/fountain/core"
                destdir="${src.java.dir}/com/databottling/fountain/core"
                includes="Constants.java"
                debug="${debug}"
        />

where <property name="src.java.dir" value="src"/>

If there is a Constants.class in the destdir, javac will overwrite that with the newly created .class. If there isn't, javac creates a com/databottling/fountain/core/Constants.class inside destdir, which isn't what I want.

The javac command line being generated is

Using classic compiler
Compilation args: [-d, C:\user\work\databottling\fountain\src\com\databottling\fountain\core, -classpath, C:\user\work\databottling\fountain\src\com\databottling\fountain\core;C:\JRu n\jre\lib\ext\QTJava.zip;C:\b\jdk1.2.2\lib\tools.jar;C:\user\java\jakarta-an t\lib\ant.jar;C:\user\java\jakarta-ant\lib\xml.jar;C:\user\java\jakarta-tomc at-3.1\lib\servlet.jar;C:\user\java\jakarta-tomcat-3.1\lib\webserver.jar;C:\ user\java\xerces-1_0_3\tools\xerces-1.0.1.jar;C:\user\java\jgl3.1.0\lib\jgl3 .1.0.jar;C:\user\java\ecs-1.2\bin\ecs-1.2.jar;C:\user\java\castor-0.8\castor -0.8.jar;C:\user\work\databottling\fountain\src, -sourcepath, C:\user\work\databottling\fountain\src\com\databottling\fountain\core, -g]
Files to be compiled:
C:\user\work\databottling\fountain\src\com\databottling\fountain\core\C C:\user\work\databottling\fountain\src\com\databottling\fountain\core\Consta nts.java


Trying this out at the command line, it looks like if the -d option is left off then javac will put the Constants.class file in the same directory as the source.

I made a patch to javac.java to suppress -d in the case where srcdir and destdir are the same place, but I'm an Ant newbie and am looking for any guidance available.

Steve Peterson

--- src\org\apache\tools\ant\taskdefs\javac.java        Tue Apr 18 14:53:08 2000
+++ src\main\org\apache\tools\ant\taskdefs\javac.java   Thu Apr 27 10:11:24 2000
@@ -355,17 +355,21 @@
         if (deprecation == true)
             argList.addElement("-deprecation");

-        argList.addElement("-d");
-        argList.addElement(destDir.getAbsolutePath());
+       String destPath = destDir.getAbsolutePath();
+       String srcPath = srcDir.getAbsolutePath();
+       if (!destPath.equals(srcPath)) {
+         argList.addElement("-d");
+         argList.addElement(destPath);
+       }
         argList.addElement("-classpath");
         // Just add "sourcepath" to classpath ( for JDK1.1 )
         if (Project.getJavaVersion().startsWith("1.1")) {
             argList.addElement(classpath + File.pathSeparator +
-                               srcDir.getAbsolutePath());
+                               srcPath);
         } else {
             argList.addElement(classpath);
             argList.addElement("-sourcepath");
-            argList.addElement(srcDir.getAbsolutePath());
+            argList.addElement(srcPath);
             if (target != null) {
                 argList.addElement("-target");
                 argList.addElement(target);



--
Steve Peterson                               +1 952 948 9729
Principal Consultant                     FAX +1 612 677 3050
Virtation Technologies, Inc.            http://virtation.com



Reply via email to