配置maven指定的JDK版本
-
第一种(最省事):在我们安装maven环境的conf目录下修改settings.xml文件,如下:
在profiles中加入以下配置。<profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile>
-
第二种:在我们开发工具eclipse中添加配置也可以实现,具体配置如下:
<properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>
-
第三种:还是在eclipse中添加配置,和第二种不一样的是我们通过maven的插件实现,
具体配置如下:<build> <plugins> <!-- 设置编译版本 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins>
三种方式均可实现指定JDK版本,第一种最省事,不过以后创建的maven项目都会默认
选择JDK1.8了,在开发中我们可以自己在pom文件中配置,可以随时切换JDK版本。