Browse Source

Add extra diags on the error message by printing out java.home

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@421585 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 19 years ago
parent
commit
c08f713b3c
3 changed files with 26 additions and 13 deletions
  1. +4
    -1
      src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java
  2. +14
    -12
      src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java
  3. +8
    -0
      src/main/org/apache/tools/ant/util/JavaEnvUtils.java

+ 4
- 1
src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java View File

@@ -110,7 +110,10 @@ public final class CompilerAdapterFactory {
+ " is not on the "
+ "classpath.\n"
+ "Perhaps JAVA_HOME does not"
+ " point to the JDK");
+ " point to the JDK.\n"
+ "It is currently set to \""
+ JavaEnvUtils.getJavaHome()
+ "\"");
}
}
}


+ 14
- 12
src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java View File

@@ -23,6 +23,8 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.taskdefs.LogOutputStream;
import org.apache.tools.ant.types.Commandline;

@@ -34,6 +36,7 @@ import org.apache.tools.ant.types.Commandline;
* @since Ant 1.3
*/
public class Javac12 extends DefaultCompilerAdapter {
protected static final String CLASSIC_COMPILER_CLASSNAME = "sun.tools.javac.Main";

/**
* Run the compilation.
@@ -48,7 +51,7 @@ public class Javac12 extends DefaultCompilerAdapter {
try {
// Create an instance of the compiler, redirecting output to
// the project log
Class c = Class.forName("sun.tools.javac.Main");
Class c = Class.forName(CLASSIC_COMPILER_CLASSNAME);
Constructor cons =
c.getConstructor(new Class[] {OutputStream.class,
String.class});
@@ -63,11 +66,15 @@ public class Javac12 extends DefaultCompilerAdapter {
new Object[] {cmd.getArguments()});
return ok.booleanValue();
} catch (ClassNotFoundException ex) {
throw new BuildException("Cannot use classic compiler, as it is "
+ "not available. A common solution is "
+ "to set the environment variable"
+ " JAVA_HOME to your jdk directory.",
location);
throw new BuildException("Cannot use classic compiler , as it is "
+ "not available. \n"
+ " A common solution is "
+ "to set the environment variable"
+ " JAVA_HOME to your jdk directory.\n"
+ "It is currently set to \""
+ JavaEnvUtils.getJavaHome()
+ "\"",
location);
} catch (Exception ex) {
if (ex instanceof BuildException) {
throw (BuildException) ex;
@@ -76,12 +83,7 @@ public class Javac12 extends DefaultCompilerAdapter {
ex, location);
}
} finally {
try {
logstr.close();
} catch (IOException e) {
// plain impossible
throw new BuildException(e);
}
FileUtils.close(logstr);
}
}
}

+ 8
- 0
src/main/org/apache/tools/ant/util/JavaEnvUtils.java View File

@@ -414,4 +414,12 @@ public final class JavaEnvUtils {
}
return script;
}

/**
* Return the value of ${java.home}
* @return the java home value.
*/
public static String getJavaHome() {
return JAVA_HOME;
}
}

Loading…
Cancel
Save