簡體   English   中英

NetBeans項目中的exec-maven-plugin Java版本不同於maven-compiler-plugin Java版本

[英]exec-maven-plugin Java version different from maven-compiler-plugin Java version in NetBeans project

我啟動 NetBeans IDE 12.0 系統環境 JAVA_HOME (1.8) 低於 IDE 使用 (14)。 The IDE output window of Maven execution seems to show that the project is run with JAVA_HOME for JDK 14, running project files this way.

But the exec-maven-plugin fails with java.lang.UnsupportedClassVersionError: com/mycompany/Start has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

This seems to indicate that Maven runs under 1.8 in the IDE, ignoring the IDE's own override setting of JAVA_HOME of 14. It uses the JDK as set in JAVA_HOME, because if I set JAVA_HOME to 14.0 before IDE startup then it works.

我正在尋找正確的方法,正確的位置,專門為任何項目設置 JDK,無論 IDE 啟動時活動的 JAVA_HOME 設置如何。

通過運行安裝了 JDK 14.0 但 JAVA_HOME 設置為 1.8 的 IDE 12.0 可以重現我的案例。 在 IDE 啟動之前。 I use the Maven project generated from the command at https://wicket.apache.org/start/quickstart.html - all set to defaults. 要運行的文件是 Start.java。

這對我很重要,因為我必須使用不同的 JDK 打開許多不同的項目,因此每次使用不同的 JAVA_HOME 設置重新啟動 IDE 是不切實際的。 事實上,我的設置似乎定義不明確 - 我一定遺漏了一些東西。

我應該在項目屬性中添加它,我已按預期將 Build|Compile|Java Platform 設置為 JDK 14(默認)。

我已經提交了NetBeans 問題

對於 maven,如果您希望項目的字節碼為 1.8,請嘗試僅設置編譯器插件使用的變量,即使您使用的是較新的 JDK。

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.htmlZ

如果您想要完全安裝不同的 java,那么您可能需要查看工具鏈。 但如果上述方法不能滿足您的需求,我只會選擇 go 這條路線。 https://maven.apache.org/guides/mini/guide-using-toolchains.html

我不熟悉 NetBeans 但希望它能讀取 maven 的編譯器級別。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM