1

Using Eclipse with the m2eclipse plug-in, how do I update the pom.xml, so the “Maven->Update Project” won’t reset the project configuration back to Java 1.5? I am using Eclipse Kepler 4.3, Java 7, and the m2eclipse plug-in. I create a new Maven project with “Create a simple project (skip archetype selection)” checked and the artifactId “test”. I get the following warning.

Description Resource Path Location Type Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment. test Build path JRE System Library Problem

I use the following steps the change the compiler from 1.5 to 1.7. 1. On the project, do right-click “Properties” and select the “Java build path”. 2. Go to the “Libraries” tab. 3. Remove the old JRE System Library [JavaSE-1.5]. 4. Click “Add Library…”, select “JRE System Library”, and click “Next>”. 5. Check “Execution environment” radio button and select “JavaSE 1.7 …” from the adjoining menu. 6. Click “Finish” 7. Click “OK”.

The warning disappears.

I right-click the project and select “Maven->Update Project”. I click “OK”.

The warning message returns.

My understanding is the plugin uses the pom.xml to update Eclipse’s current settings. How do I update the pom.xml, so the “Maven->Update Project” won’t reset the project configuration back to Java 1.5?

I looked at these pages, but I think the answers are obsolete. Warning - Build path specifies execution environment J2SE-1.4 What causes a new Maven project in Eclipse to use Java 1.5 instead of Java 1.6 by default and how can I ensure it doesn't? maven does not compile in java 1.6

For example, adding …

<configuration> <source>1.7</source> <target>1.7</target> </configuration>

… after the version section in the POM doesn’t fix the problem.

Community
  • 1
  • 1
user2686879
  • 11
  • 1
  • 1
  • 2

2 Answers2

1

You need to use the maven compiler plugin.

<build>
    <plugins>
        <!-- Tell maven to compile using Java 1.7 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>
codethulhu
  • 3,976
  • 2
  • 21
  • 15
  • I updated pom.xml to look like this.` 4.0.0 com.aglx test 0.0.1-SNAPSHOT org.apache.maven.plugins maven-compiler-plugin 3.1 1.7 1.7 `This did NOTsolve the problem. – user2686879 Aug 15 '13 at 20:36
  • 2
    1. You're missing the build tag around your plugins. 2. Comments are a terrible place to put code snippets. – codethulhu Aug 15 '13 at 20:46
0

You'll need to set the Maven Compiler Plugin to use a specific version

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>
</plugins>
</build>
Diogo Moreira
  • 1,082
  • 2
  • 9
  • 24