解决Maven更新后错误Dynamic Web Module 3.0 requires Java 1.6 or newer

今天在用Maven->Update Project更新项目后,出现Dynamic Web Module 3.0 requires Java 1.6 or newer错误提示,发现项目Java Compiler中的版本回到1.5,如图所示。在Maven官方文档找到了原因。Maven 3.0 source和target的默认设置都是1.5,与运行Maven时的JDK版本无关,除非在项目的POM文件中显示的指定一个版本,否则每次更新后都会使用编译器默认的source/target版本1.5。


解决方案,在POM中添加source和target编译版本

<!-- 官方文档 -->
<!-- http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html -->
<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>3.3</version>
			<configuration>
				<!-- 指定source和target的版本 -->				
				<source>1.8</source>
				<target>1.8</target>
			</configuration>
		</plugin>
	</plugins>
</build>





发布了91 篇原创文章 · 获赞 40 · 访问量 86万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章