Reputation: 1145
does anybody know how Maven do its compilation task? I know that Ant looks for "tools.jar" in the classpath and use "com.sun.tools.javac.Main" as entry point for the compiler.
What about Maven? Thanks.
Upvotes: 2
Views: 118
Reputation: 1145
Just to let you know, the javac compiler (if you specify 'javac' as target compiler, obviously), used inside the maven compiler plugin, is loaded in this way:
first of all, he try to load it from the classpath. If no compiler is found, he try to load it from lib/tools.jar, inside the directory "java.home" (the system property). It's like ANT does, more or less.
This is the snippet from org.codehaus.plexus.compiler.javac.JavacCompiler:
private static final String JAVAC_CLASSNAME = "com.sun.tools.javac.Main";
...
...
...
try {
return JavacCompiler.class.getClassLoader().loadClass( JavacCompiler.JAVAC_CLASSNAME );
} catch ( ClassNotFoundException ex ) {
// ok
}
final File toolsJar = new File( System.getProperty( "java.home" ), "../lib/tools.jar" );
if ( !toolsJar.exists() ) {
throw new CompilerException( "tools.jar not found: " + toolsJar );
}
// then, he load the class using a URLClassLoader
Upvotes: 1
Reputation: 9069
The maven-compiler-plugin takes control of this as the following mentioning: -
Maven Compiler Plugin The Compiler Plugin is used to compile the sources of your project. The default compiler is javac and is used to compile Java sources. Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.
I hope this may help.
Upvotes: 1