【问题标题】:Maven compilationMaven编译
【发布时间】:2013-03-05 19:55:30
【问题描述】:

有人知道 Maven 是如何完成它的编译任务的吗? 我知道 Ant 在类路径中查找“tools.jar”并使用“com.sun.tools.javac.Main”作为编译器的入口点。

Maven 呢?谢谢。

【问题讨论】:

    标签: maven ant javac


    【解决方案1】:

    maven-compiler-plugin 对此进行了控制,如下所述:-

    Maven 编译器插件 Compiler Plugin 用于编译项目的源代码。默认编译器是 javac,用于编译 Java 源代码。另请注意,目前默认源设置为 1.5,默认目标设置为 1.5,与运行 Maven 的 JDK 无关。如果您想更改这些默认值,您应该按照Setting the -source and -target of the Java Compiler 中的说明设置源和目标。

    我希望这会有所帮助。

    【讨论】:

    • 感谢您的帮助。如果您想了解更多详细信息,请查看我的回答
    【解决方案2】:

    让您知道,在 maven 编译器插件中使用的 javac 编译器(显然,如果您将 'javac' 指定为目标编译器)以这种方式加载:

    首先,他尝试从类路径中加载它。如果没有找到编译器,他会尝试从目录“java.home”(系统属性)中的 lib/tools.jar 加载它。 这和 ANT 差不多。

    这是来自org.codehaus.plexus.compiler.javac.JavacCompiler的sn-p:

    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
    

    【讨论】:

      猜你喜欢
      • 2010-11-04
      • 2012-11-29
      • 2014-12-28
      • 2021-06-25
      • 2020-07-16
      • 2012-10-28
      • 2015-08-30
      • 2016-10-27
      • 1970-01-01
      相关资源
      最近更新 更多