0

I have downloaded a web application project onto my Mac OSX 10.8.2 and I am using the Apache ant to compile it. I am getting this error when the application is running, attempting to compile-and-execute a JSP:

javax.servlet.ServletException: java.lang.UnsupportedClassVersionError
Unsupported major.minor version 51.0

I have searched for this problem on the web, and it seems this problem is caused by the compiled version being different from the running version of Java. All the suggested solutions are to "set the compiler version in Eclipse," but I am not using Eclipse...

This is my environment:

java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

How can I check the ant-compiled version(s) of my class files and resolve this problem?

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
chanjianyi
  • 607
  • 4
  • 15
  • 35
  • 1
    You need to be clearer about how you're running the project. I strongly suspect you'll find that Tomcat's actually running using Java 6. – Jon Skeet Feb 08 '13 at 11:39
  • 1
    This is because the project was build on the lower version. You need to downgrade your version when you're running your program – asifsid88 Feb 08 '13 at 11:41

2 Answers2

3

This problem is because you have compiled the code on a higher version of java and then running the code on a lower version of java. Usually the servers ship with their own version of JVM. So one way to find the jvm used by your server is to check the startup logs of your server. It should show the jvm version.

Ramadas
  • 510
  • 2
  • 7
2

UnsupportedClassVersionError is mainly because of the java version mismatch between running and compile versions .

Both versions should match in order to avoid the error GO through the below link to get more details about the ant version change.

Why is Ant giving me a Unsupported major.minor version error

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307