diff --git a/docs/manual/CoreTasks/javac.html b/docs/manual/CoreTasks/javac.html index 05bc9c0c2..7632c863b 100644 --- a/docs/manual/CoreTasks/javac.html +++ b/docs/manual/CoreTasks/javac.html @@ -191,8 +191,11 @@ files/directories from the CLASSPATH it passes to the compiler.

fork - whether to execute Javac using the JDK compiler externally; - defaults to no. + whether to execute Javac using the JDK compiler + externally; defaults to no. You can also give a + complete path to the javac executable to use instead of + yes, which would run the compiler of the Java + vesrion that is currently running Ant. No @@ -251,6 +254,26 @@ href="../using.html#path">path-like structures and can also be set via neste directory, and stores the .class files in the ${build} directory. The classpath used contains xyz.jar, and debug information is on.

+ +
  <javac srcdir="${src}"
+         destdir="${build}"
+         fork="true"
+  />
+

compiles all .java files under the ${src} +directory, and stores the .class files in the +${build} directory. This will fork off the javac +compiler using the default javac executable.

+ +
  <javac srcdir="${src}"
+         destdir="${build}"
+         fork="java$$javac.exe"
+  />
+

compiles all .java files under the ${src} +directory, and stores the .class files in the +${build} directory. This will fork off the javac +compiler using the executable named java$javac.exe. Note +that the $ sign needs to be escaped by a second one.

+
  <javac srcdir="${src}"
          destdir="${build}"
          includes="mypackage/p1/**,mypackage/p2/**"
diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java
index d7d81bdb1..d12e1fd7c 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Javac.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java
@@ -63,6 +63,7 @@ import org.apache.tools.ant.util.GlobPatternMapper;
 import org.apache.tools.ant.util.SourceFileScanner;
 import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;
 import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory;
+import org.apache.tools.ant.taskdefs.condition.Os;
 
 import java.io.File;
 
@@ -118,7 +119,8 @@ public class Javac extends MatchingTask {
     private Path extdirs;
     private boolean includeAntRuntime = true;
     private boolean includeJavaRuntime = false;
-    private boolean fork = false;
+    private String fork = "false";
+    private String forkedExecutable = null;
     private boolean nowarn = false;
     private String memoryInitialSize;
     private String memoryMaximumSize;
@@ -452,20 +454,40 @@ public class Javac extends MatchingTask {
 
     /**
      * Sets whether to fork the javac compiler.
-     */
-    public void setFork(boolean fork)
-    {
-        this.fork = fork;
+     *
+     * @param f "true|false|on|off|yes|no" or the name of the javac
+     * executable.
+     */
+    public void setFork(String f) {
+        if (f.equalsIgnoreCase("on")
+            || f.equalsIgnoreCase("true")
+            || f.equalsIgnoreCase("yes")) {
+            fork = "true";
+            forkedExecutable = getSystemJavac();
+        } else if (f.equalsIgnoreCase("off")
+                   || f.equalsIgnoreCase("false")
+                   || f.equalsIgnoreCase("no")) {
+            fork = "false";
+        } else {
+            fork = "true";
+            forkedExecutable = f;
+        }
     }
 
     /**
      * Is this a forked invocation of JDK's javac?
      */
     public boolean isForkedJavac() {
-        return fork || 
+        return !"false".equals(fork) || 
             "extJavac".equals(project.getProperty("build.compiler"));
     }
 
+    /**
+     * The name of the javac executable to use in fork-mode.
+     */
+    public String getJavacExecutable() {
+        return forkedExecutable;
+    }
 
     /**
      * Sets whether the -nowarn option should be used.
@@ -519,7 +541,7 @@ public class Javac extends MatchingTask {
 
         String compiler = project.getProperty("build.compiler");
 
-        if (fork) {
+        if (!"false".equals(fork)) {
             if (compiler != null) {
                 if (isJdkCompiler(compiler)) {
                     log("Since fork is true, ignoring build.compiler setting.",
@@ -611,4 +633,24 @@ public class Javac extends MatchingTask {
             "javac1.4".equals(compiler);
     }
 
+    protected String getSystemJavac() {
+	// This is the most common extension case - exe for windows and OS/2, 
+        // nothing for *nix.
+	String extension =  Os.isFamily("dos") ? ".exe" : "";
+
+	// Look for java in the java.home/../bin directory.  Unfortunately
+	// on Windows java.home doesn't always refer to the correct location, 
+	// so we need to fall back to assuming java is somewhere on the
+	// PATH.
+	java.io.File jExecutable = 
+            new java.io.File(System.getProperty("java.home") +
+                             "/../bin/javac" + extension );
+
+	if (jExecutable.exists() && !Os.isFamily("netware")) {
+	    return jExecutable.getAbsolutePath();
+	} else {
+	    return "javac";
+	}
+    }
+    
 }
diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java b/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java
index 4b48563b7..49d8a5c36 100644
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java
@@ -56,7 +56,6 @@ package org.apache.tools.ant.taskdefs.compilers;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.condition.Os;
 import org.apache.tools.ant.types.Commandline;
 
 /**
@@ -73,7 +72,7 @@ public class JavacExternal extends DefaultCompilerAdapter {
         attributes.log("Using external javac compiler", Project.MSG_VERBOSE);
 
         Commandline cmd = new Commandline();
-        cmd.setExecutable(getJavacExecutableName());
+        cmd.setExecutable(getJavac().getJavacExecutable());
         setupModernJavacCommandlineSwitches(cmd);
         int firstFileName = cmd.size();
         logAndAddFilesToCompile(cmd);
@@ -81,25 +80,5 @@ public class JavacExternal extends DefaultCompilerAdapter {
         return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
     }
 
-    private String getJavacExecutableName() {
-	// This is the most common extension case - exe for windows and OS/2, 
-        // nothing for *nix.
-	String extension =  Os.isFamily("dos") ? ".exe" : "";
-
-	// Look for java in the java.home/../bin directory.  Unfortunately
-	// on Windows java.home doesn't always refer to the correct location, 
-	// so we need to fall back to assuming java is somewhere on the
-	// PATH.
-	java.io.File jExecutable = 
-            new java.io.File(System.getProperty("java.home") +
-                             "/../bin/javac" + extension );
-
-	if (jExecutable.exists() && !Os.isFamily("netware")) {
-	    return jExecutable.getAbsolutePath();
-	} else {
-	    return "javac";
-	}
-    }
-    
 }