2

I'm converting some of our projects into Maven projects, but m2e changes my .classpath JRE entry from:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>

to:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>

This causes a few errors like:

Description Resource Path Location Type Access restriction: The type WindowsPopupMenuSeparatorUI is not accessible due to restriction on required library C:\Program Files\Java\jdk1.6.0_20\jre\lib\rt.jar DottedJPopupMenuSeparator.java /acommons/src/com/ks/acommons/gui/lookandfeel line 10 Java Problem

Is there any way I can make m2e not generate the .classpath file, or force it to use the workspace default JDK?

Jared
  • 2,043
  • 5
  • 33
  • 63
  • See also: https://stackoverflow.com/questions/14804945/maven-build-path-specifies-execution-environment-j2se-1-5-even-though-i-chang – Aaron Digulla Dec 20 '17 at 14:34

3 Answers3

3

In my opinion, Maven is helping you here. It forces Eclipse to use a strict Java 1.6 environment and prevents you from using libraries which are not part of the standard distribution.

Typically this error message is hinting that you should be declaring a new Maven dependency, rather than relying on a JAR file being present in (e.g.) JRE/lib/ext.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • I wound up changing the error into a warning for now in Eclipse, while I work with the owners of the offending code. – Jared Sep 14 '12 at 14:46
0

This is currently not possible, but it may be if m2e bug 405661 is fixed.

As of today (m2e 1.5.0.20140606-0033), you can only configure m2e to preserve additional classpath entries, but it will always clobber the ones that it automatically generates. This includes the classpath entry for the JRE, so there is no way to set this entry manually and have it survive an m2e project update.

oberlies
  • 11,503
  • 4
  • 63
  • 110
0

You need to configure Maven to use the correct JRE.

What you're doing is you configured Eclipse to use a certain JRE and now you expect Maven to use the same. This doesn't work because Maven will use the POM (pom.xml) to determine which JRE to use. That makes sense since Maven is a command line tool which runs outside of Eclipse. m2e just configures Eclipse to behave similarly as Maven from the command line. As you can see, Maven is in control here, Eclipse is not!

To make the two work with each other, you need to configure the Maven compiler plugin like so:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source> <!-- JRE version that you need -->
                <target>1.8</target>
            </configuration>
        </plugin>

That will tell Maven which JRE version you want. Now you can configure a matching JRE version in Eclipse preferences and m2e will configure the Eclipse compiler to use the one which has the correct version.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820