无法在Eclipse IDE中“Maven生成”我的Java项目

qoefvg9y  于 2023-02-11  发布在  Java
关注(0)|答案(1)|浏览(209)

我有一个正在运行的Java项目(实际上只有2个JAVA文件),需要在Maven或Gradle中构建。由于我是在Eclipse IDE for Java DelpersKepler Service Release 220140224-0627),I found this article to add Maven to my Java Project.中编写Java项目的
将Maven添加到我的项目后,我必须遵循这个SO答案,以允许自己正确地右键单击项目-〉Maven-〉Update Project...。(感谢这个如此的回答)。但是现在当我右键单击项目-〉Run As-〉Maven Install时,我得到了以下内容:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building AMC 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ RobTillmanProject ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Users\names\workspace\paging-mission-control\AMC\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ RobTillmanProject ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 2 source files to D:\Users\names\workspace\paging-mission-control\AMC\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.050s
[INFO] Finished at: Tue Feb 07 16:35:15 EST 2023
[INFO] Final Memory: 8M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project RobTillmanProject: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[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

根据错误,看起来我需要向Installed JREs列表(just as this SO answer suggests)添加JDK。
在Eclipse IDE中,我安装了Windows-〉Preferences-〉Java-〉Installed JREs,在PC上的C:\Program Files\Java文件夹中,我安装了jdk-17jdk-17.0.6jdk-19.0.2。当我添加任何一个JDK时(我已经尝试了JRE类型Standard 1.1x VMStandard VM),我得到错误消息Target is not a JDK root. System library was not found.
我在Windows 10上运行Eclipse IDE。
有什么建议吗?

e3bfsja2

e3bfsja21#

确保在“已安装的JRE”部分中添加JDK主目录的正确位置。

例如,我使用JDK 8并选择JDK作为默认,如下所示:

确保您也更改了编译器版本以使用与您的JDK匹配的版本。另一方面,例如您使用maven clean install来构建项目,则确保maven发行版使用正确的JAVA_HOME。
在Eclipse中,再次转到窗口/首选项/ Maven /安装
选择您的本地maven发行版,而不是使用Eclipse的嵌入版本,例如:

您可以通过键入cmd来检查您的maven发行版是否使用了正确的JDK:mvn -version,例如在我的Windows中,我使用JDK 11,如以下输出所示:

希望这能帮上忙。请告诉我。

相关问题