Question

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?

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top