Monday, July 16, 2012

class file has wrong version 50.0, should be 49.0″ by Maven

If this error occurs when you’re compiling your Maven project, there’s a good chance that you’ve included a Maven Dependency that was compiled using Java 1.6 and your Maven installation is running on a Java 1.5 JRE.
The good news is that Maven will tell you which Dependency is causing that. For instance, in my case it was java-web-api as shown in the error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project hTask-web: Compilation failure
[ERROR] /Users/hordine/projects/hTask/hTask-web/src/main/java/com/hordine/htask/web/control/TaskController.java:[3,-1] cannot access javax.servlet.http.HttpServletRequest
[ERROR] bad class file: /Users/hordine/.m2/repository/javax/javaee-web-api/6.0/javaee-web-api-6.0.jar(javax/servlet/http/HttpServletRequest.class)
[ERROR] class file has wrong version 50.0, should be 49.0
This makes perfect sense, since if you use features of a later java version, i.e. 1.6, to build your application, then those features won’t be understood by an earlier Java JRE, i.e. 1.5, since they didn’t know what was coming in Java 1.6 yet. Yeah right.
But anyway, there are 2 quick ways to fix this. One is to find an earlier version of your Dependency, which was compiled using Java 1.5, and the other is to install a Java 1.6 JRE and get Maven to use that one. The later can be as simple as setting the JAVA_HOME environment variable to your Java 1.6 installation.
That’s it for this post.

http://hordine.wordpress.com/2012/05/02/class-file-has-wrong-version-50-0-should-be-49-0-by-maven/

No comments:

Post a Comment