有人知道Maven是如何完成编译任务的吗?我知道Ant在类路径中查找"tools.jar“,并使用"com.sun.tools.javac.Main”作为编译器的入口点。
那Maven呢?谢谢。
发布于 2013-03-06 08:34:16
maven-compiler-plugin对此进行控制,如下所述:
编译器插件编译器插件用于编译项目的源代码。默认编译器是javac,用于编译Java源代码。还要注意,目前缺省的源设置是1.5,缺省的目标设置是1.5,独立于运行Maven的JDK。如果要更改这些默认值,则应按照Setting the -source and -target of the Java Compiler中的说明设置源和目标。
我希望这能有所帮助。
发布于 2013-03-06 20:45:16
为了让您知道,在maven编译器插件中使用的javac编译器(显然,如果您指定'javac‘作为目标编译器)是这样加载的:
首先,他尝试从类路径加载它。如果没有找到编译器,他会尝试从目录"java.home“(系统属性)中的lib/tools.jar加载它。就像蚂蚁一样,或多或少。
这是来自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 URLClassLoaderhttps://stackoverflow.com/questions/15232903
复制相似问题