What javac.exe is used by ant javac task?

I ran into one problem. I renamed javac.exe to my machine and noticed that the ant javac task is still working fine.

Does anyone know where to get it from javac.exe?

+3
source share
2 answers

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 .

This means that if the tools.jar library is in the current path to the Ant classes, it will grab the class and run it. This leads to the fact that javac.exe can be renamed to what you want, it will work anyway. Therefore, to answer your question, it actually does not execute any “javac.exe”.

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

+6
source

You can try to run here and check what is configured in the build.compiler global property, it can point elsewhere

-1
source

Source: https://habr.com/ru/post/920847/


All Articles