maven(15)------maven打包时报错Fatal error compiling: 无效的目标发行版: 1.8.0_91

时间:2020-12-26 00:03:33

对于刚接触maven的朋友,喜欢兴冲冲的从官网下载一个maven,开始构建maven项目,

等使用maven打包的时候,出现如下错误:

[WARNING] The requested profile "jdk-1.8" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:

compile (default-compile) on project springboot: Fatal error compiling: 无效的目标发行版: 1.8.0_91 -> [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/MojoExecutionException

出现这个问题的最好解决办法就是在maven下setting.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>
注意,根据你的jdk版本进行配置,这里使用的jdk8.

另外一种解决办法就是在pom.xml文件中显示指定jdk版本:

<build>  
<plugins>
<!-- 编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>

如果采用以上某个解决方案还是出现同样的问题,哪就是项目编译设置问题:

选中项目-->“右键”-->"Properties"-->"Java Build Path"-->"JRE System Library..."-->"Edit"选择你安装的jdk:

maven(15)------maven打包时报错Fatal error compiling: 无效的目标发行版: 1.8.0_91

如果还有问题,可能就是java环境变量没配置好,

或者maven中配置的jdk版本与java环境变量配置的版本不一致!