優(yōu)質(zhì)博文IT-BLOG-CN
目前部分項(xiàng)目使用JDK8
,部分項(xiàng)目使用JDK19
因此,環(huán)境變量中還是保持JDK8
,只需要下載JDK19
免安裝版本,通過配置IDEA
就可以完成本地開發(fā)。
一、IDEA 環(huán)境設(shè)置
【1】通過快捷鍵CTRL + SHIFT + ALT + S
或者File->Project Structure...
設(shè)置SDK
和Language level
,不存在JDK19
時(shí)可通過Edit
添加
【2】設(shè)置下方的Modules
中的Sources
模塊和Dependencies
模塊
【3】設(shè)置下方的Platform Setting
中的SDKs
模塊
【4】設(shè)置File->Settings...
中的Build,Excepotion,Deployment
下的Builder Tools->Maven->Runner
模塊【5】設(shè)置
File->Settings...
中的Build,Excepotion,Deployment
下的Compiler->Java Compiler
模塊【6】如果使用了
Tomcat
點(diǎn)擊Edit Configurations...
后,設(shè)置JRE
模塊
【7】設(shè)置完成后通過
Maven
插件進(jìn)行編譯,因?yàn)橥ㄟ^控制臺(tái)執(zhí)行mvn
命令時(shí)使用的是本地環(huán)境變量中配置的JDK
版本,而Maven
插件使用的是IDEA
中配置的JDK
版本。
二、POM依賴修改
在項(xiàng)目父模塊的pom.xml
中添加如下plugin
文章來源:http://www.zghlxwxcb.cn/news/detail-825746.html
<properties>
<maven.compiler.plugin.version>3.10.1</maven.compiler.plugin.version>
<java.version>19</java.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgument>--enable-preview</compilerArgument>
<compilerVersion>${java.version}</compilerVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<argLine>
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.lang.reflect=ALL-UNNAMED
--add-opens java.base/sun.reflect.annotation=ALL-UNNAMED
--add-opens java.base/java.math=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED
--add-opens java.base/sun.util.calendar=ALL-UNNAMED
--add-opens java.base/java.io=ALL-UNNAMED
--add-opens java.base/java.net=ALL-UNNAMED
--add-opens java.xml/com.sun.org.apache.xerces.internal.jaxp.datatype=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
后面遇到最多的就是項(xiàng)目包的沖突問題,依次解決就好文章來源地址http://www.zghlxwxcb.cn/news/detail-825746.html
到了這里,關(guān)于JDK8 升級至JDK19的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!