在Maven项目(Eclipse)中更改JDK [英] Change JDK in Maven Projects (Eclipse)
问题描述
新的 Maven 项目使用默认的JRE系统库"J2SE-1.5".
New Maven projects created in Eclipse (on Windows) use the default JRE System Library "J2SE-1.5".
该项目是通过以下方式创建的:
The project was created the following way:
- 新项目
- Maven-> Maven项目
- Archtype:maven-archetype-quickstart
我想使用 JDK 1.8.0 ,这是非Maven项目的默认JDK.
我的 JAVA_HOME 变量设置为
I want to use the JDK 1.8.0, which is my default JDK for non Maven projects.
My JAVA_HOME variable is set to
C:\ Program Files \ Java \ jdk1.8.0_152
C:\Program Files\Java\jdk1.8.0_152
我尝试通过右键单击系统库来切换系统库,并将路径设置为我的 JDK 1.8.0 .但是在Maven更新之后,它会重置为1.5.
I tried switching the system library via Right Click on the System Library and set the path to my JDK 1.8.0. But after a Maven update it resets back to the 1.5.
其他Stackoverflow问题仅建议设置JAVA_HOME,但这对我不起作用.指定供Maven使用的JDK
我寻找了一些 POM.xml 命令来设置库,但是找不到任何东西.我的POM现在看起来很标准:
Other Stackoverflow questions just suggest to set the JAVA_HOME, but that did not work for me. Specify JDK for Maven to use
I looked for some POM.xml commands to set the library, but couldn't find anything. My POM looks pretty standard right now:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>Test123</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test123</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
要使JDK 1.8成为默认库,我需要更改什么?
What do I need to change to get the JDK 1.8 as my default Library?
推荐答案
在pom.xml中设置JDK:
Set the JDK in the pom.xml:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
在Eclipse中执行"Maven->更新项目"
in eclipse do a 'Maven->Update Project'
这篇关于在Maven项目(Eclipse)中更改JDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!