zoukankan      html  css  js  c++  java
  • 如何在maven pom.xml文件中设置Java编译器版本

    今天遇到一个问题:

    在Eclipse中用maven创建一个新的web项目,然后再用maven update一下,则JDK版本自动变为1.5。

    通过查找资料,终于发现maven编译器插件(Maven Compiler Plugin)的文档中有如下解释:

    The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.

    Also note that 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. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.

    有两种方式可以设置编译器版本。以下是pom.xml文件的代码片段:

    第一种方法:

    <project>
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
    </project>

    第二种方法:

    <project>
        <build>
        <plugins>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
            </plugin>
        </plugins>
        </build>
    </project>

    最后在eclipse里面右键点击项目,使用maven重新更新项目即可。

  • 相关阅读:
    CodeForces
    POJ1113 Wall —— 凸包
    UVA11330 Andy's Shoes —— 置换分解
    FZU2013 A short problem —— 线段树/树状数组 + 前缀和
    fzu月赛 2203 单纵大法好 二分
    codeforces 519E A and B and Lecture Rooms LCA倍增
    hdu 5459 Jesus Is Here (费波纳茨递推)
    zoj 3469 Food Delivery 区间dp + 提前计算费用
    hdu5438 Ponds dfs 2015changchun网络赛
    hdu5432 二分
  • 原文地址:https://www.cnblogs.com/yitouniu/p/7569812.html
Copyright © 2011-2022 走看看