0

I'm trying to get an existing project building using maven and m2eclipse. I've created a new maven project for it and imported my source files and added necessary dependencies, but I'm getting compile errors because it's defaulting to using Java 1.5 settings. I've tried updating the pom.xml file to instruct the system to use Java 1.7, following which I've told eclipse to update the project settings from maven, closed and reopened the project, and restarted eclipse to see if it would flush the information that Java 1.5 should be used, but eclipse is still insisting that the project should be compiled with 1.5. My pom.xml file is pasted below:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>uk.org.dsf</groupId>
    <artifactId>util-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>util-test</name>
    <description>utility classes for testing purposes</description>
    <plugin> <!-- enable java 1.7 -->
        <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>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.jmock</groupId>
            <artifactId>jmock</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.jmock</groupId>
            <artifactId>jmock-junit4</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
            <version>3.3.1</version>
        </dependency>
    </dependencies>
</project>

Any ideas what's going wrong here?

Jules
  • 14,841
  • 9
  • 83
  • 130
  • can you check project properties of eclipse to see what version has been set / selected there – Satya May 12 '14 at 06:49
  • Eclipse is saying J2SE-1.5, but it must be getting that information from Maven, because my workspace default is 1.7. And isn't it supposed to update the eclipse settings from the pom whenever the pom changes? – Jules May 12 '14 at 06:51
  • Have you looked at this: http://stackoverflow.com/questions/14804945/maven-build-path-specifies-execution-environment-j2se-1-5-even-though-i-chang?rq=1 – DanielBarbarian May 12 '14 at 09:02
  • Yes, but I'm somewhat confused as the answer is fundamentally at odds with answers to other similar questions (e.g. https://stackoverflow.com/questions/3032628/m2eclipse-sets-jdk-compliance-to-1-4) which suggest that you should make the change via pom.xml and m2eclipse should automatically adjust the eclipse settings, which is what the documentation seems to suggest should be happening. I'm reluctant to perform a change manually every time I start a new project when that change should be happening automatically. – Jules May 18 '14 at 11:11
  • Also note: what I state I have done above is identical to what is suggested by the highest rated (rather than the accepted) answer on that question. There seems to be some degree of confusion as to what is supposed to happen here, and it would be good to get a straight answer as to what is going wrong. – Jules May 18 '14 at 11:12

1 Answers1

0

The POM file quoted above is malformed. The <plugin> tag should be nested inside a <build><plugins> block; m2eclipse is therefore unable to find the compiler details from it. The only strange thing here is that this doesn't produce any kind of error or warning message; it should at the least be resulting in a warning that the XML file doesn't conform to its specified schema.

Another related problem I've encountered: if you specify a java version > 1.7 in eclipse Juno, the value is ignored, even if you have a Java 8 JDK configured. It appears 1.8 only works correctly in Luna, and perhaps Kepler with some updates installed (haven't tested that configuration).

Jules
  • 14,841
  • 9
  • 83
  • 130