15

For developing a JavaFX application I'm using a 4.3.1 snapshot of eclipse together with JDK 8 build b116. In my workspace projects the JRE library inclusion in the build path get resetted back to Java 1.4 all the time:

the problem

Unfortunately, this can only be fixed temporary (until the next eclipse restart):

the temporary solution

In the build section of my pom files I have:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <debug>true</debug>
        <debuglevel>source,lines</debuglevel>
    </configuration>
</plugin>

I'd appreciate a less volatile solution.

[UPDATE] The issue seems to be fixed with the current versions of

  • Java 8 (1.8.0-ea-b121),
  • Maven (3.1.1/1.5.0.20131218-0705),
  • m2e (1.5.0.20131218-1208) together with the
  • JDT beta patch [Update site].
Cœur
  • 37,241
  • 25
  • 195
  • 267
Jens Piegsa
  • 7,399
  • 5
  • 58
  • 106
  • Change the java version in project facet to 1.8. May be you can try to run the eclipse to use java 1.8( I don't think this will have any impact). Pom.xml dependency looks fine – Karthik Prasad Nov 22 '13 at 14:01
  • @Jens have you been able to resolve this issue? I am in the same situation now with Eclipse 4.3, Maven 3.2.1 and JDK 1.8.0b129. – FuryFart Feb 26 '14 at 21:48
  • @RAM: I update my post with some details about my current (working) versions, hopefully that helps. – Jens Piegsa Feb 26 '14 at 22:07
  • The Install Instructions from https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_%28BETA%29 seem to work. I can use Java 8 features but the Execution Environment of the Maven project is still listed as J2SE-1.4. – FuryFart Feb 27 '14 at 08:20
  • Same problem as http://stackoverflow.com/questions/22696067/eclipse-4-3-2-with-java-8-patches-doesnt-recognize-source-level-1-8/23003292#23003292 ;) – Lenny May 09 '14 at 10:09

1 Answers1

2

The maven eclipse plugin (m2e) selects a java execution environment depending on the <source> and <target> properties for the maven compiler plugin.

The problem is that there is neither a 1.8 execution environment available in Kepler nor the m2e maven compiler connector can map it yet.

Thus I see two solutions until it is supported in Kepler and m2e:

  1. Let maven change the environment to 1.4 and map your 1.8 JDK to the execution environment J2SE-1.4. Then your project will use the correct JDK. But then all projects that depend on 1.4 will use the 1.8 JDK of course.

  2. Use the pluginManagenent to turn off the maven-compiler-plugin lifecycle handling. This should prevent the m2e plugin from updating the execution environment and you can set it manually.

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                     <lifecycleMappingMetadata>
                           <pluginExecutions>
                                 <pluginExecution>
                                     <pluginExecutionFilter>
                                           <groupId>org.apache.maven.plugins</groupId>
                                           <artifactId>maven-compiler-plugin</artifactId>
                                           <versionRange>[1.0.0,)</versionRange>
                                         <goals>
                                             <goal>compile</goal>
                                         </goals>
                                     </pluginExecutionFilter>
                                     <action>
                                          <ignore />
                                     </action>
                                 </pluginExecution>
                           </pluginExecutions>
                     </lifecycleMappingMetadata>
               </configuration>
           </plugin>
        </plugins>
    </pluginManagement>
    
René Link
  • 48,224
  • 13
  • 108
  • 140
  • Thanks for the comprehensive answer. It looks like the second option solves the problem. It just worries me a little, that Mavens *Updating Project* now throws an `java.lang.NullPointerException at org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionFilter.match(PluginExecutionFilter.java:337)` ... – Jens Piegsa Nov 22 '13 at 15:58
  • 1
    Hmm, that was not what I expected. I will take a look at it later or tomorrow. – René Link Nov 22 '13 at 16:01
  • 1
    I also got the NPE and updated my answer. The NPE should be gone now and you should still be able to set the execution environment manually. – René Link Nov 23 '13 at 16:35
  • Thanks for coming back to this. Now, the pom file editor shows the error `Cannot parse lifecycle mapping metadata for maven project`. :-/ – Jens Piegsa Nov 23 '13 at 18:05
  • 1
    @JensPiegsa The parse exception you have is caused by the `goals` and `versionRange` tag. I updated my answer. But if the `lifecycleMappingMetadata` is correct than m2e will update the execution environment again. Thus it does not work to use the `lifecycleMappingMetadate` to turn it off. So there is only one option left, nr. 1 as I proposed. Hope that helps you anyway. – René Link Nov 24 '13 at 12:37
  • Well, with option 1, I have to correct the compliance level manually. Thanks for the effort, though. Let us be patient until Eclipse, Maven and m2e officially support version 8. – Jens Piegsa Nov 24 '13 at 15:51