Eclipse Maven 项目问题: Dynamic Web Module 3.0 requires Java 1.6 or newer.

问题描述:
这里写图片描述

但是Eclipse 的编译级别并没有问题。
这里写图片描述

原因:
Maven maven-compiler-plugin 的编译问题。Maven 的默认编译级别是 jdk1.5 或以下。
所以,还有一个现象,就是每次右键项目名-maven->update project 时候,项目jdk版本变了,变回1.5版本。

解决方法1:
修改maven的配置(Maven安装目录的conf\setting.xml)
搜索找到profile节点。替换为下面的代码。

<profile>
    <id>jdk1.8</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
    </activation>
    <properties>
        <!-- want to use the Java 8 language features, Default 1.5 -->
        <maven.compiler.source>1.8</maven.compiler.source>
        <!-- want the compiled classes to be compatible with JVM 1.8, Default 1.5 -->
        <maven.compiler.target>1.8</maven.compiler.target>
        <!-- Version of the compiler to use, ex. "1.3", "1.5", if fork is set to true -->
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
</profile>

解决方法2:
修改项目中的pom.xml
添加:

<build>
<plugins>
    <!--
        指定maven插件编译版本
        1:maven:since2.0, 默认用jdk1.3来编译,maven 3.x 貌似是默认用jdk 1.5。 
        2:windows默认使用GBK编码,java项目经常编码为utf8,也需要在compiler插件中指出,否则中文乱码可能会出现编译错误。 
     -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <!-- since 2.0 -->
        <version>3.7.0</version>
        <configuration>
            <!-- use the Java 8 language features -->
            <source>1.8</source>
            <!-- want the compiled classes to be compatible with JVM 1.8 -->
            <target>1.8</target>
            <!-- The -encoding argument for the Java compiler. -->
            <encoding>UTF8</encoding>
        </configuration>
    </plugin>
</plugins>
</build>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值