How do I resolve a java.lang.UnsupportedClassVersionError?

Abstract: How do I resolve a java.lang.UnsupportedClassVersionError?

Issue:

When I attempt to run my Servlet, I receive the following exceptions:

javax.servlet.ServletException: Error allocating a servlet instance
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:185)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:653)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:534)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.doTask(ProcessorTask.java:403)
com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:55)

root cause java.lang.UnsupportedClassVersionError: untitled1/Servlet1 (Unsupported major.minor version 49.0)
java.lang.ClassLoader.defineClass0(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:537)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1774)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:905)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1370)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1234)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:185)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:653)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:534)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.doTask(ProcessorTask.java:403)
com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:55)

How do I resolve this issue?

Solution:

This exception can occur when the source is built targeting a JDK that is not supported by the JDK attempting to run it. In the above example, if the servlet was built targeting only JDK 1.5, but the web server runs JDK 1.4, the above exception will occur.

Check, Project Properties | Build | Java | Target VM, and verify that the Target VM indicates a JDK compatibility that is appropriate for the JDK that is running it. It is recommended to set this field to 'All Java SDKs' for the most compatibility. The only reason you would want to specify a particular version is if your code uses language features that only appear in a particular verison of the JDK, and you want to ensure that users use only a compatible JDK.

Also check, Project Properties | Build | Java | Language Features, and verify that the Language Features are applicable with JDK that is running it.