Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm setting up a Tomcat server to host JSP sites. I have created a test application in Eclipse to make sure everything is working. All it does is print text in JSP, then call a function in a custom class which also prints text. This runs fine in Eclipse (running on the same computer as Tomcat), put when I compile the program into a WAR file and try to run it from Tomcat, it throws the exception:

message javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: jsp/test/TestClass : Unsupported major.minor version 51.0 (unable to load class jsp.test.TestClass)

description The server encountered an internal error that prevented it from fulfilling this request.

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: jsp/test/TestClass : Unsupported major.minor version 51.0 (unable to load class jsp.test.TestClass)
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
    ...

root cause

javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: jsp/test/TestClass : Unsupported major.minor version 51.0 (unable to load class jsp.test.TestClass)
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
    ...

root cause

java.lang.UnsupportedClassVersionError: jsp/test/TestClass : Unsupported major.minor version 51.0 (unable to load class jsp.test.TestClass)
    org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2899)
    ...

I should point out that once I refresh the page, the error changes to just UnsupportedClassVersionError and looses the "major.minor" stuff. Not sure what's going on there.

Google has told me that this has to do with the runtime being an older version than the compiler however as far as I can tell, both Eclipse and Tomcat are using the most recent. They are on the same computer, so they should be using the same JAVA_HOME variable right? I have a number of different JRE / JDK installations and I've tried several of them as JAVA_HOME though nothing seemed to change (I am restarting Tomcat each time). As of right now it is:

JAVA_HOME = C:\Program Files\Java\jdk1.7.0_25
Path = C:\Program Files\Java\jdk1.7.0_25\bin; ...

Is there anything else that needs to be set for Tomcat to use this version of Java? Or is there a different location I need to point JAVA_HOME to? I have tried several of the JRE installations as well but come up with nothing. Any ideas with this?

This is all being done on Windows Server 2008 R2 using Tomcat 7.

Thanks in advance.

Doug

share|improve this question

3 Answers 3

In Eclipse, go to your Project Preferences, go to the Java Compiler settings.

What is the compiler compliance level?

If you are running this with Tomcat 7 with Java 7 then the compliance level should be set at 1.7. If it is not, then that may be your issue. Although it should be fine as long as it is <= 1.7, you wouldn't per chance have configured eclipse for a snapshot of Java 8?

Either way, knowing this value may help illuminate the issue.

share|improve this answer
    
The compiler compliance level is set to 1.7. I haven't done anything involving Java 8. –  Doug Sep 2 '13 at 19:57
    
Also make sure project facets (right-click on project => properties => Project facets) has Java 1.7. –  Jukka Sep 3 '13 at 20:38
    
In project facets the three things checked are Dynamic Web Module - 3.0, Java - 1.7, and JavaScript - 1.0. That seems to be good, I dunno if the other two versions have anything to do with this. –  Doug Sep 3 '13 at 20:48

UnsupportedClassVersionError always appears when you compile "with" one version (targeting one version) and execute with a previous java version.

JAVA_HOME does not tell the operating system where should it look for the java.exe file. The operating system will take that file from the PATH variable. That's why it's recommended to add at the beginning of the PATH variable, the path JAVA_HOME/bin.

If it is not the case, the stacktrace (the rest of the error message) could be useful. In particular the "Unsupported major.minor" or something like that, and the numbers.

Additional information.

share|improve this answer
    
I changed the path to C:\Program Files\Java\jdk1.7.0_25\bin and moved that location to the beginning of the variable (It was set to just C:\Program Files\Java\jdk1.7.0_25 prior). Unfortunately, I've got no change. I also edited the stack trace into the question. Not sure how I managed to forget that. –  Doug Sep 3 '13 at 15:23
    
OK. It says that, for whatever reason, you are not executing with Java 7. I understand you would have restarted after the change in PATH. Could you please type java -version in the command line? –  Gonzalo Sep 3 '13 at 16:09
    
I restarted Tomcat after changing the path, and when that didn't work I restarted the computer, still nothing though. java -version gives me: java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b17) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode) It looks like it's using the right version. –  Doug Sep 3 '13 at 16:18
    
Yeah. Do you have set JRE_HOME? Apparently when JRE_HOME and JAVA_HOME are both set, Tomcat uses JRE_HOME. –  Gonzalo Sep 3 '13 at 19:09
    
I do not have JRE_HOME set as anything. It's not in the list, so I don't think it is interfering unless I need it for something. –  Doug Sep 3 '13 at 19:50

How are you deploying your code to Tomcat, via Eclipse (WTP) or are you building a WAR with a particular build tool and the manually deploying it to a local Tomcat?

share|improve this answer
    
I am coding it in Eclipse (where it runs fine), then exporting it to a WAR file and copying it to Tomcat's webapps directory where it gets deployed. I can see it unpack the WAR file, so I know that much is working. –  Doug Sep 3 '13 at 19:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.