Monday, March 9, 2015

Compiler version error

I get the below error once in a while. And its frequent enough to annoy me and to warrant a note on it.
Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.UnsupportedClassVersionError: WEB9032: Class com.xxxx.yyyyy.MainController has unsupported major or minor version numbers, which are greater than those found in the Java Runtime Environment version 1.6.xxxx. Please see server.log for more details.

This is mainly caused by compiling some of my classes using the a different version Java compiler. This happens sometimes when I create a new Intellij IDEA project for the same source code and I forget to set the Java SDK correctly.

To prevent this, simply force Maven to use the correct compiler version. Then nothing can possibly go wrong.

<build>
    <finalName>MyProject</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>