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
  • 相关阅读:
    CopyOnWriteArrayList 读写分离,弱一致性
    Java中定时器Timer致命缺点(附学习方法)
    排队打饭:公平锁和非公平锁(面试)
    母鸡下蛋实例:多线程通信生产者和消费者wait/notify和condition/await/signal条件队列
    volatile,synchronized可见性,有序性,原子性代码证明(基础硬核)
    Synchronized用法原理和锁优化升级过程(面试)
    Java中多线程安全问题实例分析
    iOS 相互引用引起内存泄露问题说明
    iOS app 集成友盟推送问题
    ios即时通讯客户端开发之-mac上基于XMPP的聊天客户端开发环境搭建
  • 原文地址:https://www.cnblogs.com/zno2/p/4583178.html
Copyright © 2011-2022 走看看