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
  • 相关阅读:
    .NET数据库编程求索之路11.一些思考
    VMware Workstation安装使用手记
    VS2010无法保存项目文件(.csprj)的问题解决方法
    【转】VC++/MFC(VC6)开发技术精品学习资料下载汇总 (2011.3.10更新)
    .NET数据库编程求索之路9.使用EF实现
    oracle11g新特性:闪回数据归档(Flashback Data Archive)#ocp试验#
    ORACLE口令文件验证与操作系统验证|转|
    闪回flashback#ocp试验#
    expdp数据泵导出操作
    手动模式下热备份的不完全恢复#OCP试验#
  • 原文地址:https://www.cnblogs.com/zno2/p/4583178.html
Copyright © 2011-2022 走看看