tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Thomas <>
Subject Re: Tomcat 5.5 JDK version compatibility
Date Thu, 08 Mar 2012 19:59:40 GMT
On 08/03/2012 19:33, David Wahler wrote:
> On Thu, Mar 8, 2012 at 12:58 PM, Caldarale, Charles R
> <> wrote:
>>> From: David Wahler []
>>> Subject: Tomcat 5.5 JDK version compatibility
>>> Does this mean that if a web application is deployed in Tomcat 5.5,
>>> it may not use any language features that were introduced in J2SE
>>> 5.0 or later (e.g. annotations and generics), even if those features
>>> are supported by the JRE?

It means that *if* you do that, you run the risk that your application
that claims to be a Servlet 2.4 application will not run on a
specification compliant Servlet 2.4 container. Therefore, your
application is not specification complaint.

You can compile with a later JRE and take advantage of features
available in the newer JRE version but you then place additional
restrictions on the JRE that the container can use over and above those
defined in the specification.

>> It's not the JRE that's the issue, it's the servlet spec version that your webapp
is claiming compliance with.  Annotations don't appear there until 2.5 (if I remember correctly).
 Generics will likely work, because there's nothing in the servlet spec related to those.
> True, neither annotations nor generics are mentioned in the servlet
> 2.4 spec, but both are supported at the language level by JRE/JDK 5
> and up. In particular, my test case refers to
> @javax.annotation.Resource, which is part of J2SE 6 and understood by
> dependency-injection frameworks like Spring and Guice. But as per
> Servlet 2.5, that annotation is also interpreted by Tomcat 7 and used
> to inject JNDI dependencies. My expectation was that Tomcat's
> annotation processing would only happen if web.xml referred to version
> 2.5 of the spec or later.
> Hence the question: does the fact that annotations are a Java 5
> feature automatically make a webapp that uses them non-compliant with
> servlet spec 2.4?
> (Mark seems to be assuming that I compiled my test case against Tomcat
> 7 APIs and then tried to deploy the resulting app with Tomcat 5.5,
> which isn't the case.)

There is no way you compiled an application that uses
javax.annotation.Resource against the Servlet 2.4 / Java EE 1.4 API. If
you try that you'll get an error.

If you compile against a later API, claim to use an older API and then
run on a container that supports the later API then you should expect
some odd behaviour and that is exactly what you got. Tomcat is never
going to add the necessary checking to prevent this because of the
overhead it adds to fix what is a build time issue.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message