您的位置:首页 > 编程语言 > Java开发

Maven 修改默认JDK版本和指定项目JDK版本

2014-12-09 14:18 435 查看
问题源于我在安装maven以后没有做过任何的设置,使用命令mvn install的时候得到了error: generics are not supported in -source 1.3和error: for-each loops are not supported in -source 1.3, 第一感觉就是JDK出现了问题(错误原因显然应该是用JDK1.3编译了),但是项目的JDK设置的就是1.7,语言也是7.0。

这里有两个办法(全局设定和单工程设定)可以解决问题。

1. 全局设定就是修改maven的配置文件,应该先找到你的maven安装目录,我用的是linux, mvn -v就能知道path。



在conf文件夹下找到settings.xml在profiles 节点下增加:

<profile>
    <id>jdk-1.7</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.7</jdk>
    </activation>
    <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
    </properties>
</profile>
就好了,这里配置的是1.7, 你可以修改成任何你需要的版本。

2. 工程设定就是在你maven工程的pom.xml文件中加入plugin.

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
这样本工程maven就会使用1.7去编译了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: