Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 330356

Summary: Tomcat server adaptor does not welcome JDK endorsed libraries
Product: [WebTools] WTP ServerTools Reporter: Dmitry Katsubo <dma_k>
Component: wst.serverAssignee: Larry Isaacs <larryisaacs>
Status: RESOLVED WONTFIX QA Contact: Angel Vera <arvera>
Severity: normal    
Priority: P3 CC: ccc
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Tomcat launch configuration (with endorsed libraries manually included) none

Description Dmitry Katsubo CLA 2010-11-16 09:34:00 EST
Build Identifier: JST Server Adapters 3.2.2.v20100818b-777HFGRCcNBDiBjIbhBA8

I my configuration I have only one jdk1.6.0_03 in "Java" --> "Installed JREs". This JDK contains the endorsed libraries for JAXB 2.1 (because 1.6.0_03 comes with JAXB 2.0):

ls -1 "C:\Program Files\JAVA\jdk1.6.0_03\jre\lib\endorsed\"
jaxb-api-2.1.jar
jaxws-api-2.1.jar

Tomcat launch configuration uses this JDK. Unfortunately, endorsed libraries are not included when Tomcat is launched, causing the failure during applications' deployment.

The workaround is to manually include the necessary libraries into the configuration (supposed to be done automatically).

Reproducible: Always
Comment 1 Dmitry Katsubo CLA 2010-11-16 09:34:54 EST
Created attachment 183222 [details]
Tomcat launch configuration (with endorsed libraries manually included)
Comment 2 Larry Isaacs CLA 2011-01-03 14:22:21 EST
Sorry to take so long to respond.  It is designed behavior in Tomcat itself that the "java.endorsed.dir" property is set to reassign the "endorsed" directory to something other than the JRE or JDK's "\lib\endorsed" directory.  This allows Tomcat to control what get picked up via the "endorsed" directory and avoid being impacted by undesirable content that may happen to be in the JRE or JDK's "endorsed" directory.  The support for Tomcat in WTP maintains this behavior.  The runtime configuration for Tomcat servers in WTP will specify the same "endorsed" directory that Tomcat would use, i.e. "<CATALINA_HOME>\endorsed".  Note that this directory is optional and doesn't exist in newer Tomcat versions.  It was once needed in older Tomcat versions to provide a newer XML parser than the JRE (1.4) provided by default.   Jars in the appropriate "endorsed" directory, once created, should be picked up.

Since I won't be changing current behavior to match what is requested in this bug, I'm marking it as WONTFIX.
Comment 3 Dmitry Katsubo CLA 2011-01-04 10:24:52 EST
Larry, thank you for comments.

Eclipse can for example show a warning that JDK endorsed folder contains the libraries which are not in boot classpath of Tomcat, and/or show the confirmation dialog asking to include endorsed libraries to Tomcat launch configuration.

If it is possible to re-rate this bug as "extension", I would appreciate.
Comment 4 Larry Isaacs CLA 2011-01-04 10:53:24 EST
My understanding is that the "endorsed" directory serves a specific purpose, which is to provide a means of overriding JRE runtime classes with different classes to effectively "update" or "alter" the JRE.  Tomcat's use provides a good example of using it for this purpose.  The 1.4 JRE's provided either a pre-2.0 XML parser or one that was buggy.  Tomcat needed one that reliably supported 2.0, so it used the "endorsed" folder to provide a XML parser known to work.  Without a reason like this, putting jars in the "endorsed" directory is likely a bad idea, in spite of the convenience.

Jars such as the ones you list are best included directly in the "WEB-INF/lib" of any Dynamic Web Project that needs them.  There are various ways of referencing the jars so that you don't have to duplicate them an each project.  This is consistent with web service based Dynamic Web Projects, which include the needed jars per project via a facet.  So, before bothering to change this bug to an enhancement, you would need to provide a really good reason why putting the jars in "WEB-INF/lib" isn't appropriate in your use case. :)
Comment 5 Dmitry Katsubo CLA 2011-01-04 14:59:03 EST
Larry, thank you for comments.

There is a real ground to put these libraries in endorsed, please refer 7.1.2 here: http://jaxb.java.net/guide/Migrating_JAXB_2_0_applications_to_JavaSE_6.html
Perhaps JAXB is really an extreme case but (as you have mentioned) there might be a need to replace other JDK parts, like XML parser or SAAJ API.

The current situation is that:
- Unit tests are run OK under Eclipse, because is was launched by "patched" JDK
- When I start Tomcat as a standalone server - everything works.
- But when I start Tomcat as embedded server via adapter - the application fails.

Perhaps automatic propagation of endorsed libraries is a bad idea, but giving a hint + quickfix never hurts.
Comment 6 Larry Isaacs CLA 2011-01-04 15:55:00 EST
I'm curious how the standalone Tomcat works since it also ignores the JDK/JRE "lib/endorsed" by setting the "java.endorsed.dirs" system property.  Is the standalone Tomcat by any chance using a newer JDK that already has the 2.1 JAXB built in?  

There wouldn't be much chance of getting a quick fix or hint implemented given my limited cycles to contribute to WTP, unless you wanted to contribute a patch.  The Tomcat adapter just adds the "java.endorsed.dirs" system property to the launch configuration and, like Tomcat itself, doesn't worry about any unexpected side effects.  Handling of the JVM aspects of the launch configuration is left to other portions of Eclipse.  Adding such code to the Tomcat adapter, while not difficult, would not qualify as simple.
Comment 7 Dmitry Katsubo CLA 2011-01-06 15:13:44 EST
Yes, you are right: standalone Tomcat needs "JAVA_ENDORSED_DIRS" system property to be defined for endorsed feature to work. In this sense it does not differ from embedded.

I was thinking about the warning message (or hint) in "Run configuration". If you say it is difficult to discover a potential problem with endorsed in that dialog, leave this bug as closed. At least there is a not-so-difficult workaround.