eclipse建maven项目在命令行窗口编译出错[ERROR] 不再支持源选项 5。请使用 7 或更高版本。

首先编译出如下错误

[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< edu.zut.sc.software:teach >----------------------
[INFO] Building teach 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ teach ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ teach ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\Java\EclipseProjects\teach\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] 不再支持源选项 5。请使用 7 或更高版本。
[ERROR] 不再支持目标选项 5。请使用 7 或更高版本。
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.445 s
[INFO] Finished at: 2020-03-02T20:42:22+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project teach: Compilation failure: Compilation failure:
[ERROR] 不再支持源选项 5。请使用 7 或更高版本。
[ERROR] 不再支持目标选项 5。请使用 7 或更高版本。
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

分析:可能是maven不了解当前jdk版本而出错

解决方案:

在maven项目中的pom.xml文件中的< project >标签中添加以下内容:

声明以下:由于我的jdk版本是13.0.2,因此我填的13.
  <properties>
  	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 	 <maven.compiler.source>13</maven.compiler.source>
 	 <maven.compiler.target>13</maven.compiler.target>
</properties>

此博文只用于记录博主学习过程(有问题可评论)

猜你喜欢

转载自blog.csdn.net/qq_46043634/article/details/104620102