zoukankan      html  css  js  c++  java
  • 12) maven-compiler-plugin

    The Compiler Plugin is used to compile the sources of your project. 

    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. 

    Change these defaults:

    <project>
      [...]
      <build>
        [...]
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
            </configuration>
          </plugin>
        </plugins>
        [...]
      </build>
      [...]
    </project>

    http://maven.apache.org/components/plugins/maven-compiler-plugin/

    注意事项1:

    除了配置这个插件,如果是在eclipse中,Installed Jres 需要存在1.7 ,不然实际使用的jdk不是1.7 。

    举例说明:eclipse 中只有1.6 和 1.8 

     

    配置成1.7 ,但实际使用的是选中的1.8

    如果存在1.7 ,实际使用的则是1.7(默认的仍然是1.8)

    注意事项2:

    在命令行中执行是使用的环境变量配置的 JAVA_HOME

    测试新建了一个 Maven项目,指定1.8 ,在类中使用1.8特有的 java.util.stream.Stream 

    然后修改环境变量到1.7 , 用命令行执行 mvn compile 显示编译失败

    F:eworkspace_FP_ebiscusz-test2>mvn compile
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building z-test2 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ z-test2 ---
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] Copying 0 resource
    [INFO]
    [INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ z-test2 ---
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
    [INFO] Compiling 1 source file to F:eworkspace_FP_ebiscusz-test2	argetclasses
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.141 s
    [INFO] Finished at: 2016-12-19T15:44:02+08:00
    [INFO] Final Memory: 8M/105M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project z-test2: Fatal error compiling: inva
    lid target release: 1.8 -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  • 相关阅读:
    magic_quotes_gpc(魔术引号开关)
    获取文件绝对路径:__FILE__与 $_SERVER[SCRIPT_FILENAME''] 的 区别
    小程序wx:key中的关键字*this
    swiper 更改indicator-dots 属性 隐藏面板指示点
    B站视频下载
    makefile教程
    Qt 中配置 c99的问题
    C语言编译过程及相关文件
    go语言入门(10)并发编程
    go语言入门(9)文本文件处理
  • 原文地址:https://www.cnblogs.com/zno2/p/4583178.html
Copyright © 2011-2022 走看看