4

How do I stop maven from constantly updating my Java System Library from JDK 1.8 back to Java SE 1.8? I have configured the build path and I even set my Java_Home Variable to the JDK path. I have also have updated the build configuration. Can someone please specify how to do this with some specific instructions as I am a novice. I also noticed this keeps changing back as well. FYI I am using Eclipse Mars if that matters.

In Regards to the comments below I have shared the Eclipse M2e Plugin screenshot. Even when selected I am not able to proceed to next. I also have shown what's already installed just in case another plugin is hindering me from using the m2e enter image description here

Andy Williams
  • 879
  • 1
  • 14
  • 33
  • As far as runtime behavior is concerned jdk1.8.0_60 and jdk 1.8.0_60 are the same thing. I think you are trying to solve a "non-problem". – Stephen C Oct 14 '15 at 12:11
  • Did you restart eclipse after setting `JAVA_HOME` (note: caps) – vikingsteve Oct 14 '15 at 12:14
  • Yes I have done so, I just did again to double check. I then updated maven project again and it resets to the the Java SE. An to Stephen's Question I was under the impression JAVA SE 1.8 and JDK 1.8 our perceived to be different classpaths. – Andy Williams Oct 14 '15 at 12:22
  • Maven does not change anything in your Eclipse installation. Thsi is clearly an Eclipse problem. – Michael-O Oct 14 '15 at 12:39
  • What gives you that impression? – Stephen C Oct 14 '15 at 12:39
  • @Michael-O - Actually ... it could be the Eclipse m2e plugin that is doing it. But you are correct. The m2e plugin is not Maven. – Stephen C Oct 14 '15 at 12:41
  • So if it could be the Eclipse m2e plug in, any recommendations? – Andy Williams Oct 14 '15 at 12:43
  • I also added a screenshot above – Andy Williams Oct 14 '15 at 12:49
  • @StephenC It is highly unlikely that m2e does that. If your Eclipse runs off a JRE, it will warn you about. Nothing more will happen. – Michael-O Oct 14 '15 at 12:51
  • So if its an ecplise issue are there any recommendations? I have no idea what else to do. – Andy Williams Oct 14 '15 at 12:59
  • FYI, `JAVA_HOME` has no impact in Eclipse. Eclipse can be told what JVM to run in via `eclipse.ini`, and applications you develop in Eclipse are configured by workspace preferences (see my answer below) – E-Riz Oct 14 '15 at 13:03
  • @Michael-O - On the contrary. When you run the "Maven > Update Project", the m2e plugin is going to tweak the Eclipse project preferences to match what the POM file requires. One of the things that the POM file can select is the target Java version for the build, and the way that Eclipse would implement is by changing the corresponding Java project preferences. – Stephen C Oct 14 '15 at 13:09
  • @StephenC Yes but it does not fiddle with your Java installations. – Michael-O Oct 14 '15 at 13:13
  • @Michael-O - Apparently, it does. See the accepted answer. – Stephen C Oct 14 '15 at 13:23

1 Answers1

6

You need to understand what an Execution Environment (EE) is in Eclipse. The concept of EE is an abstraction over JREs, allowing projects to be configured without absolute paths to JRE locations. From the wiki page:

Execution environments (EEs) are symbolic representations of JREs. For example, rather than talking about a specific JRE, with a specific name at a specific location on your disk, you can talk about the J2SE-1.4 execution environment. The system can then be configured to use a specific JRE to implement that execution environment.

In general, it's not advisable to configure a project to use "Workspace default" as its JRE System Library, because that makes the project inconsistent when loaded into different workspaces. Think about this: what if the project is being developed targeting Java 7, but I pull it into my workspace which has JDK 8; that could be a big problem. By using an EE, the project is configured such that it doesn't know (or care) where I actually have a matching JRE on my system.

I said all that to set up the answer for you, so you understand what Maven is doing and these instructions are doing. m2e, the Maven integration plugin for Eclipse, is (rightly) setting the project configuration to use an EE instead of "workspace default". From your screen shot I can see that you have both JDK and JRE 1.8 set up in your workspace, so ideally you should remove one (the JRE). Got to Preferences > Java > Installed JREs. There you'll see both the JRE and JDK listed. I suggest removing the JRE*.

Then go into the "Execution Environments" preferences section, select JavaSE-1.8 and make sure that your JDK is checked as the default implementation.

Now when m2e configures your projects to use an EE, that EE will be pointing to the JDK you have installed. And if someone else imports the project, it will point to wherever they have a matching JDK installed.

*By the way, it's perfectly acceptable and normal to have different versions of Java there; I often work on different projects that target different Java versions.

Community
  • 1
  • 1
E-Riz
  • 31,431
  • 9
  • 97
  • 134
  • 1
    Thank you for the very detailed answer with the background info! That fixed it! – Andy Williams Oct 14 '15 at 13:13
  • 1
    Just an addition: you don't need to remove the JRE. Since Maven only switches from "Workspace default" to "Execution environment" you just need to configure the default JRE your execution environment is pointing at. So you just need to _"go into the "Execution Environments" preferences section, select JavaSE-1.8 and make sure that your JDK is checked as the default implementation"_. – Luke Nov 01 '17 at 16:33