3

I am facing one problem. I renamed javac.exe on my machine and noticed that ant javac task still works fine.

Does anybody know from where its getting javac.exe?

Andrew Thompson
  • 163,965
  • 36
  • 203
  • 405
CommonMan
  • 3,760
  • 2
  • 20
  • 35
  • 1
    Did you take a look at its [documentation](http://ant.apache.org/manual/Tasks/javac.html)? – Guillaume Polet May 10 '12 at 23:08
  • 3
    It probably comes with its own copy. Out of curiosity, why did you rename javac? – Hunter McMillen May 10 '12 at 23:08
  • 2
    Check your system path & Java path. It might pick up the javac.exe from there. Something similar had happened to me. I had jdk6 & jdk7 installed, but jdk7's bin folder was in the system path & hence it was picking the java.exe from there. – Bharat May 10 '12 at 23:10
  • I did and I think javac should be somehere in my machine for ant to use it. Please correct me if I am wrong. – CommonMan May 10 '12 at 23:11
  • @Hunter one of my friend was facing an issue and out of no where he renamed this file and reported that ant task is still able to find javac – CommonMan May 10 '12 at 23:12
  • @RBK I checked everywhere (including Sky and earth :)) but still cant find javac on my machine – CommonMan May 10 '12 at 23:13
  • @Manan there are real problems out there – ant May 10 '12 at 23:17
  • Stop wondering where it is and set it explicitly using the `executable` attribute of the `javac` task. – Andrew Thompson May 10 '12 at 23:28

2 Answers2

6

Actually, I believe, that by default Ant tries to execute the java compiler class directly with this code:

try {
        Class c = Class.forName ("com.sun.tools.javac.Main");
        Object compiler = c.newInstance ();
        Method compile = c.getMethod ("compile",
            new Class [] {(new String [] {}).getClass ()});
        int result = ((Integer) compile.invoke
                      (compiler, new Object[] {cmd.getArguments()}))
            .intValue ();
        return (result == MODERN_COMPILER_SUCCESS);

    } catch (Exception ex) {
        if (ex instanceof BuildException) {
            throw (BuildException) ex;
        } else {
            throw new BuildException("Error starting modern compiler",
                                     ex, location);
        }
    }

The code came from here.

Which means that if the library tools.jar is on the current classpath of Ant, it will pickup the class and launch it. This results in the fact that javac.exe can be renamed to whatever you want, it will still work. So to answer your question, it actually executes none of any "javac.exe".

There are other implementations of the Javac task, but I think this is the default one for all compilers 1.3+

Guillaume Polet
  • 45,783
  • 4
  • 79
  • 115
  • This is not isolated. I believe Tomcat does the same thing to compile JSP's for example, if I recall correctly at least. – Patrice M. Mar 18 '14 at 22:41
-1

You could try starting here and check what is configured in global build.compiler property, it may be pointing somewhere else

dann.dev
  • 2,375
  • 3
  • 18
  • 31