Maven編譯Fatal?error?compiling:無(wú)效的目標(biāo)發(fā)行版:11問(wèn)題及解決
Maven編譯Fatal error compiling:無(wú)效的目標(biāo)發(fā)行版:11
安裝了Java11后,用其編譯多個(gè)Springboot工程,老是失敗,后來(lái)發(fā)現(xiàn)所有工程指定了java版本為java8,于是乎卸載了java11,安裝了java8,再去編譯。
其中某個(gè)工程在之前用java11編譯的時(shí)候沒(méi)有任何問(wèn)題, 但是換成java8后出現(xiàn)了以下錯(cuò)誤:
具體信息:
F:\Digital marketing\workspace-scrm\workspace-scrm\wit-gateway-app>mvn clean install package -Dmaven.test.skip=true
[INFO] Scanning for projects...
Downloading from nexus: http://......:8051/repository/maven-public/net/trueland/tcloud/scrm/common-dependencies/3.1-SNAPSHOT/maven-metadata.xml
Downloaded from nexus: http://......:8051/repository/maven-public/net/trueland/tcloud/scrm/common-dependencies/3.1-SNAPSHOT/maven-metadata.xml (621 B at 3.8 kB/s)
[INFO]
[INFO] --------------< net.trueland.tcloud.scrm:tcloud-gateway >---------------
[INFO] Building tcloud-gateway 3.1.0
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from nexus: http://......:8051/repository/maven-public/net/trueland/commons/1.1-SNAPSHOT/maven-metadata.xml
Downloaded from nexus: http://......:8051/repository/maven-public/net/trueland/commons/1.1-SNAPSHOT/maven-metadata.xml (983 B at 16 kB/s)
Downloading from nexus: http://......:8051/repository/maven-public/net/trueland/tcloud/scrm/common-base/3.1-SNAPSHOT/maven-metadata.xml
Downloaded from nexus: http://......:8051/repository/maven-public/net/trueland/tcloud/scrm/common-base/3.1-SNAPSHOT/maven-metadata.xml (996 B at 15 kB/s)
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ tcloud-gateway ---
[INFO] Deleting F:\Digital marketing\wit-gateway-app\target
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ tcloud-gateway ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 0 resource
[INFO] Copying 6 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ tcloud-gateway ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 14 source files to F:\Digital marketing\workspace-scrm\wit-gateway-app\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.305 s
[INFO] Finished at: 2022-01-12T08:43:21+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project tcloud-gateway: Fatal error compiling: 無(wú)效的目標(biāo)發(fā)行版: 11 -> [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
從網(wǎng)上查了查資料,需要指定Maven的java編譯器版本:
1.在Java 8和更早版本中指定Maven的Java編譯器
在Java 8 和更早版本開(kāi)始,可以通過(guò)兩種方式在Maven POM文件中設(shè)置Java編譯器版本:
- 通過(guò)Maven Java編譯器屬性。
- 通過(guò)Maven Java編譯器插件。
下面將具體說(shuō)明這兩種在Maven中設(shè)置Java編譯器版本的方法。
Maven Java編譯器屬性
最簡(jiǎn)單的方法是通過(guò)Maven Java編譯器屬性。
在我們工程的pom.xml文件中進(jìn)行設(shè)置,這些屬性必須包含在POM文件的properties元素中。
<properties> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> </properties>
下面是一個(gè)具體的例子:
<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.bruce</groupId> <artifactId>wit-example</artifactId> <version>0.1.0</version> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> </project>
Maven Java編譯器插件
第二種方式是通過(guò)插件:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>
下面是一個(gè)具體的例子:
<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.bruce</groupId> <artifactId>wit-example</artifactId> <version>0.1.0</version> <packaging>jar</packaging> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
2.在Java 9及以后的版本中指定Maven的Java編譯器
在Java 9和更高版本中,也要使用插件,但是要用release屬性來(lái)代替source和target屬性。
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <release>11</release> </configuration> </plugin>
Note:Maven Java編譯器插件的版本已從3.6.1更改為3.8.0
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- java警告:源發(fā)行版17 需要目標(biāo)發(fā)行版17問(wèn)題及解決
- 解決IDEA報(bào)錯(cuò)java無(wú)效的目標(biāo)發(fā)行版:22
- 解決IDEA報(bào)錯(cuò),無(wú)效的源發(fā)行版 無(wú)效的目標(biāo)發(fā)行版:22問(wèn)題
- java:?無(wú)效的目標(biāo)發(fā)行版:?20問(wèn)題解決辦法
- IDEA啟動(dòng)Springboot報(bào)錯(cuò):無(wú)效的目標(biāo)發(fā)行版:17 的解決辦法
- JAVA錯(cuò)誤:'無(wú)效目標(biāo)發(fā)行版?17'的解決方案
- IDEA導(dǎo)入外部項(xiàng)目報(bào)Error:java: 無(wú)效的目標(biāo)發(fā)行版: 11的解決方法
相關(guān)文章
教你一步到位部署運(yùn)行MyBatis3源碼(保姆級(jí))
一個(gè)框架的運(yùn)行流程從最簡(jiǎn)單的一個(gè)helloworld來(lái)看其源碼就能了解到框架的原理是什么,這篇文章主要給大家介紹了關(guān)于如何一步到位部署運(yùn)行MyBatis3源碼的相關(guān)資料,需要的朋友可以參考下2022-06-06Java線程通信中關(guān)于生產(chǎn)者與消費(fèi)者案例分析
這篇文章主要介紹了Java線程通信中關(guān)于生產(chǎn)者與消費(fèi)者案例,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-09-09Springboot實(shí)現(xiàn)前后端分離excel下載
這篇文章主要介紹了Springboot實(shí)現(xiàn)前后端分離excel下載,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11Mybatis原始執(zhí)行方式Executor代碼實(shí)例
這篇文章主要介紹了Mybatis原始執(zhí)行方式Executor代碼實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07JAVA 開(kāi)發(fā)之用靜態(tài)方法返回類名的實(shí)例詳解
這篇文章主要介紹了JAVA 開(kāi)發(fā)之用靜態(tài)方法返回類名的實(shí)例詳解的相關(guān)資料,這里主要說(shuō)明使用異常來(lái)得到類名,希望能幫助到大家,需要的朋友可以參考下2017-08-08Java中的關(guān)鍵字synchronized 詳解
這篇文章主要介紹了Java中的關(guān)鍵字synchronized,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03Java使用jxl包寫Excel文件適合列寬實(shí)現(xiàn)
用jxl.jar包,讀寫過(guò)Excel文件。也沒(méi)有注意最適合列寬的問(wèn)題,但是jxl.jar沒(méi)有提供最適合列寬的功能,上次用到寫了一下,可以基本實(shí)現(xiàn)最適合列寬。2013-11-11