8

I'm using Eclipse as IDE and Maven outside of it to keep all dependencies up to date and update the Eclipse-project as such. In Eclipse I usually specify the JRE system library as an execution environment for any Java-project, usually "JavaSE-1.6".

In the pom.xml I use the following lines:

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <projectNameTemplate>[groupId].[artifactId]</projectNameTemplate>
                <downloadJavadocs>true</downloadJavadocs>
                <wtpversion>2.0</wtpversion>
            </configuration>
        </plugin>

This seems to let Maven pick a JDK matching 1.6. It assigns its system libraries to the classpath of the project. However, it uses jdk1.6.20 directly rather than JavaSE-1.6.

Is there a way to make Maven use JavaSE-1.6 instead?


EDIT: Here's the batch file that I use to run Maven:

SET JAVA_HOME=C:\Programme\java\jdk1.6.0_20
SET MAVEN_HOME=C:\Programme\apache-maven-2.2.1
SET MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=128m
SET PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin;%PATH%

SET EXTRA_MVN_OPTS=-Dmaven.test.skip=true

CD /D "%~dp0"
cmd /c mvn %EXTRA_MVN_OPTS% eclipse:clean eclipse:eclipse
cmd /c mvn %EXTRA_MVN_OPTS% clean install
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
sjngm
  • 12,423
  • 14
  • 84
  • 114

3 Answers3

10

You can do it by setting a classpath container.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <version>2.8</version>
    <configuration>
        <classpathContainers>
           <classpathContainer>
    org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6
           </classpathContainer>
        </classpathContainers>
    </configuration>
</plugin>

Reference:

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
2

Go into Window > Preferences > Java > Installed JREs > Execution Environments

Select JavaSE-1.6, click the checkbox on the right that should indicate "perfect match"

then use "update project configuration" from the maven menu.

Dave G
  • 9,639
  • 36
  • 41
  • It already does. Other than that I'm not allowed to use the Maven-menu as it occasionally destroys the project settings. – sjngm Jan 21 '11 at 13:31
  • Which version of the maven extension are you using? More recent versions have been VERY good about that. If you're committing the .project & .classpath files to version control, probably not a good idea as eclipse+maven can update/reconfigure those based on dependencies and plugins. – Dave G Jan 21 '11 at 14:17
  • I just saw your edit and I would look at @Sean Patric Floyd's recommendation. – Dave G Jan 21 '11 at 14:18
0

Since you are using maven and eclipse, perhaps you should use M2Eclipse plugin. The maven project (built by maven by setting JAVA_HOME=C:\Program Files\Java\jdk1.6.0_23) imported in Eclipse, shows up with JRE System Library as JavaSE-1.6

Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • It would be nice to know why you would generally prefer M2Eclipse, in addition to "it works for me" for this question. – Nicolas Oct 22 '13 at 14:38