Relationship between Eclipse default JRE, project compliance and compiler used

141 Views Asked by At

I couldn't understand for some time why my Maven project wasn't building in Eclipse and presented me with "Bad version number in .class file" errors.

  • I checked all my dependencies and ensured they were built for Java 6 or lower (using this handy JAR version checking tool).
  • I opened my project properties and confirmed I had project-specific compiler settings, set to compliance level 1.6.
  • I also confirmed I had the Java 6 libraries on my build path.

Finally, I discovered the cause was related to the default JRE selected for my workspace. This was set to jdk1.5 for some reason. Setting this to something higher than this (I chose jdk1.8) solved the issue. In the end, I had to select jdk1.7 to allow my AspectJ weaving to work correctly.

My question is: why did this solve it? According to the preferences page, this setting only influences which JRE is added to the build path of newly created Java projects. I can't fathom why this would affect my ability to build my project. Any suggestions? It seems as though Eclipse uses the default JRE selection to influence what type of compiler is used.

I'm using m2e to bind Eclipse and Maven. My POM build section is as follows:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.5</version>
            <configuration>
                <complianceLevel>1.6</complianceLevel>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
0

There are 0 best solutions below