You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Wahler <dw...@indeed.com> on 2012/03/08 19:49:48 UTC

Tomcat 5.5 JDK version compatibility

Hi all, I have a question about a comment on this bug report:

https://issues.apache.org/bugzilla/show_bug.cgi?id=52545

Mark Thomas noted that:

"The application can not be compiled using a 1.4 JDK (the minimum Java version
required by Servlet 2.4) since it uses annotations. While applications may be
compiled with a later Java version, they must be compilable with the minimum
Java version."

I just want to make sure I'm understanding this correctly. 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? I looked through both the servlet 2.4 specification and
Tomcat's documentation and couldn't find anywhere this was documented,
but I may have missed something.

Thanks,
-- David

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 5.5 JDK version compatibility

Posted by Mark Thomas <ma...@apache.org>.
On 08/03/2012 20:10, David Wahler wrote:
> On Thu, Mar 8, 2012 at 1:59 PM, Mark Thomas <ma...@apache.org> wrote:
>> 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.
> 
> As I said, javax.annotation.Resource is included with J2SE 6 (as
> specified in JSR-250, "Common Annotations for the Java(tm) Platform").
> 
> http://docs.oracle.com/javase/6/docs/api/javax/annotation/Resource.html
> 
> So the code I posted compiles just fine under Java 6 with the Tomcat 5.5 APIs.

Sorry, I had missed that someone in their infinite wisdom decided to
move classes from JavaEE to JavaSE. That is certainly a recipe for a
screw-up.

Looking at the JavaSE 6 Javadoc it refers to containers everywhere which
suggests to me that this should have stayed in the JavaEE space since
the concept of a container is very much a JavaEE concept. Unfortunately,
that genie can't be put back in the bottle.

This changes my analysis but not the end result. Behaviour of those
JavaSE language features are undefined in Servlet 2.4 since they didn't
exist when it was written. Reading the JavaSE 6 javadoc certainly
suggests that they should be processed. On the other hand, from a
Servlet spec point of view they weren't introduced until 2.5. I could
construct an argument to do either. Given that not processing them is
going to be very messy, I don't see the Tomcat code changing.

Returning to an earlier point, if you want to write a 2.4 web
application and be sure that that is what you have, then you really need
to make sure that is compiles against JavaEE 1.4 using Java 1.4. That
doesn't have to be your standard build environment but it should
probably be a CI test somewhere.

Mark

>> 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.
> 
> Fair enough.
> 
> Thanks,
> -- David
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 5.5 JDK version compatibility

Posted by David Wahler <dw...@indeed.com>.
On Thu, Mar 8, 2012 at 1:59 PM, Mark Thomas <ma...@apache.org> wrote:
> 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.

As I said, javax.annotation.Resource is included with J2SE 6 (as
specified in JSR-250, "Common Annotations for the Java(tm) Platform").

http://docs.oracle.com/javase/6/docs/api/javax/annotation/Resource.html

So the code I posted compiles just fine under Java 6 with the Tomcat 5.5 APIs.

> 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.

Fair enough.

Thanks,
-- David

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 5.5 JDK version compatibility

Posted by Mark Thomas <ma...@apache.org>.
On 08/03/2012 19:33, David Wahler wrote:
> On Thu, Mar 8, 2012 at 12:58 PM, Caldarale, Charles R
> <Ch...@unisys.com> wrote:
>>> From: David Wahler [mailto:dwahler@indeed.com]
>>> 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.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 5.5 JDK version compatibility

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David,

On 3/8/12 2:33 PM, David Wahler wrote:
> On Thu, Mar 8, 2012 at 12:58 PM, Caldarale, Charles R 
> <Ch...@unisys.com> wrote:
>>> From: David Wahler [mailto:dwahler@indeed.com] 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'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.)

Without further specifics, I would agree with you: if your webapp says
it's 2.4-spec, then no annotation processing should occur (at least by
Tomcat: Spring, etc. is free to process annotations).

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9ZEggACgkQ9CaO5/Lv0PCNagCfRwlwZtaNfCTVo9IbYZfhouCy
HyUAn22/b5YgHey6hwWBpZvb0DKBWKpx
=FgjU
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 5.5 JDK version compatibility

Posted by David Wahler <dw...@indeed.com>.
On Thu, Mar 8, 2012 at 12:58 PM, Caldarale, Charles R
<Ch...@unisys.com> wrote:
>> From: David Wahler [mailto:dwahler@indeed.com]
>> 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'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.)

-- David

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Tomcat 5.5 JDK version compatibility

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: David Wahler [mailto:dwahler@indeed.com] 
> 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'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.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 5.5 JDK version compatibility

Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/3/8 David Wahler <dw...@indeed.com>:
> Hi all, I have a question about a comment on this bug report:
>
> https://issues.apache.org/bugzilla/show_bug.cgi?id=52545
>
> Mark Thomas noted that:
>
> "The application can not be compiled using a 1.4 JDK (the minimum Java version
> required by Servlet 2.4) since it uses annotations. While applications may be
> compiled with a later Java version, they must be compilable with the minimum
> Java version."
>
> I just want to make sure I'm understanding this correctly. 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? I looked through both the servlet 2.4 specification and
> Tomcat's documentation and couldn't find anywhere this was documented,
> but I may have missed something.
>

I would say that it is just useless exercise to mark application as
"2.4" but rely on newer features in it.


The issue of "servlet 2.4" compatibility is that you have some old
application that you want to run "as is" on newer Tomcat.

The "javax.annotation.Resource" class is part of annotations-api.jar
which is not present in Tomcat 5.5. So a person is not able to compile
your application if he uses correct Servlet Specification JARs.


Just open a text editor and edit your web.xml so that it specifies the
correct version.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org