-1

I have a working Java Project (literally just 2 JAVA files) that need to be built in either Maven or Gradle. Since I wrote my Java Project in Eclipse IDE for Java Delopers (Kepler Service Release 2, 20140224-0627), I found this article to add Maven to my Java Project.

After adding Maven to my project, I had to follow this SO answer to allow myself to Right Click the Project -> Maven -> Update Project... properly. If I Right Click the Project -> Run As -> Maven Clean, I get a BUILD SUCCESS (thanks to this SO answer). But now when I Right Click the Project -> Run As -> Maven Install, I get the following:

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

As per the error, it looks like I need to add a JDK to the Installed JREs list (just as this SO answer suggests).

In Eclipse IDE, Windows -> Preferences -> Java -> Installed JREs, I have jre1.8.0_333 (default) installed. On my PC, in my C:\Program Files\Java folder, I've installed jdk-17, jdk-17.0.6 and jdk-19.0.2. However, when I go to add any one of the JDKs (I've tried JRE Type Standard 1.1x VM and Standard VM), I get the error message Target is not a JDK root. System library was not found.

I'm running Eclipse IDE on Windows 10.

Any suggestions?

  • 1
    Eclipse Kepler SR2 is 9 years and 23 releases behind. Of course, it cannot recognize a Java 17 or 19 JDK released years after Eclipse Kepler. [Make sure to use the current version of Eclipse which is currently 2022-12](https://www.eclipse.org/downloads/packages/). – howlger Feb 08 '23 at 00:01
  • @howlger I installed Eclipse `Version: 2022-12 (4.26.0)`, `Build id: 20221201-1913`. I can now `Maven Install`. However, I am unable to `Maven Build`: https://ibb.co/17dm0dC (my first time with Maven, I have no idea what I need to do to make it buildable). I also receive this if I run `mvn -version` in cmd: https://ibb.co/smq4VJh – PillagingProgrammer Feb 08 '23 at 02:26
  • I should also mention: I've followed this guide https://phoenixnap.com/kb/install-maven-windows and still getting the "'mvn' is not recognized as an internal or external command, operable program or batch file." error in cmd – PillagingProgrammer Feb 08 '23 at 02:32
  • Eclipse 2022-12 comes with an embedded Maven, so you don't need to install Maven into your system (but if you do, the guide you followed is misleading: the `PATH` has to be extended with the `bin` directory of your Maven installation, e.g. by adding something like `;C:\Program Files\apache-maven-3.9.0\bin` to the end). Your question is still about Kepler which is pretty outdated. Please fix this. [Please show also your `pom.xml` and your Maven run configuration](https://stackoverflow.com/help/minimal-reproducible-example). – howlger Feb 08 '23 at 07:03

1 Answers1

0

Make sure you are adding the correct location for the JDK home in the "Installed JREs" section.

enter image description here

For instance, I am using JDK 8 and selecting the JDK as the default as below:

enter image description here

Make sure you are also changing the compiler version to use the one matching your JDK. Other side, like your are using maven clean install to build your project, then make sure the maven distribution is using the correct JAVA_HOME.

In Eclipse, go to again Window / Preferences / Maven / Installations

Select your local maven distribution instead of using the embed version with Eclipse, for instance:

enter image description here

You can check if your maven distribution is using the correct JDK by typing in a cmd : mvn -version, for example in my Windows I am using JDK 11 like you can see in the below output:

enter image description here

Hope this can help. Please let me know.

julianhs
  • 33
  • 8
  • Thank you for offering to help. Unfortunately, what you're suggesting hasn't helped. Here is the error I get when trying to add jdk-17.0: https://ibb.co/mCydkfr, and the error for trying to install `apache-maven-3.9.0`: https://ibb.co/PDyPvWD and then when I run `mvn -version`: https://ibb.co/smq4VJh . I unzipped `apache-maven-3.9.0` to my PC, so I'm not sure why "mvn" isn't recognized as installed. – PillagingProgrammer Feb 08 '23 at 00:07