diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java index 18b9dd82f..61f733be1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java @@ -282,25 +282,33 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter { } /** - * Does the command line argument processing common to classic and - * modern and adds the files to compile as well. + * Does the command line argument processing for modern. Doesn't + * add the files to compile. */ - protected Commandline setupModernJavacCommand() { - Commandline cmd = new Commandline(); + protected Commandline setupModernJavacCommandlineSwitches(Commandline cmd) { setupJavacCommandlineSwitches(cmd); - if (attributes.getSource() != null) { cmd.createArgument().setValue("-source"); cmd.createArgument().setValue(attributes.getSource()); } - + return cmd; + } + + /** + * Does the command line argument processing for modern and adds + * the files to compile as well. + */ + protected Commandline setupModernJavacCommand() { + Commandline cmd = new Commandline(); + setupModernJavacCommandlineSwitches(cmd); + logAndAddFilesToCompile(cmd); return cmd; } /** - * Does the command line argument processing common to classic and - * modern and adds the files to compile as well. + * Does the command line argument processing for classic and adds + * the files to compile as well. */ protected Commandline setupJavacCommand() { Commandline cmd = new Commandline(); 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 9aec2fc61..4b48563b7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java @@ -56,6 +56,7 @@ 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; /** @@ -72,12 +73,33 @@ public class JavacExternal extends DefaultCompilerAdapter { attributes.log("Using external javac compiler", Project.MSG_VERBOSE); Commandline cmd = new Commandline(); - cmd.setExecutable("javac"); - setupJavacCommandlineSwitches(cmd); + cmd.setExecutable(getJavacExecutableName()); + setupModernJavacCommandlineSwitches(cmd); int firstFileName = cmd.size(); logAndAddFilesToCompile(cmd); 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"; + } + } + }