• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Tomcat , problem with libraries order

 
Ranch Hand
Posts: 127
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I develop my application with FOP (Apache's formatter) on Oracle's JDeveloper 9i - there everything works OK.
But when I deploy application (through war file) to Tomcat 4.0.3, problems begin.
By this simple code I load XML file and change its encoding:
Document document;
XMLDocument xdoc;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
DocumentBuilder builder = dbf.newDocumentBuilder();
document = builder.parse(new File("report.xml"));
xdoc = (XMLDocument) document; // ERROR ON TOMCAT
String se = xdoc.getEncoding();
xdoc.setEncoding("WINDOWS-1250");
...
The marked line generates error "ClassCastException".
Both Document and XMLDocument are from the library XMLPARSERV2.JAR, which is loaded before every library FOP 0.20.3 (uses avalon-framework-4.0.jar, batik.jar, logkit-1.0.jar ,
xalan-2.0.0.jar, xerces.jar)
But the class with same name (with different beahavior) - Document.class is
also stored in batik.jar, xalan-2.0.0.jar and xerces.jar.
I think that Tomcat somewhat mixes the libraries order and takes Document.class from one of the FOP libraries instead from xmlparserv2.jar.
I am still rather new to this. Do I need to have set Classpath or something else installed, even if the application is run via web-browser ? (Now I have Tomcat and browser on one PC)
Does somebody see the solution to this ? Thanks.
 
Saloon Keeper
Posts: 28321
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat maintains about 5 different sets of classpaths internally. They have a pretty good set of documentation on what they are and how they're used at the jakarta.apache.org/tomcat site.
One reason WHY they've devoted a lot of effort to that is because serious problems happened when Tomcat needed one version of an XML library for its own internal purposes, but webapps needed another(s), so they sat down and figured out a set of rules that (more or less) makes everyone happy.
 
Jiri Nejedly
Ranch Hand
Posts: 127
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I found out that Tomcat has its own XML parsing done by xerces.jar stored in \common\lib directory and every work with Document class goes primarily through this library. Either I must replace this library with other parser (xmlparserv2.jar, which however doesn't conform to Sun's JAXP standard ) or I must not use non-standard classes like XMLDocument.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a strange sort of occurence. As I understand Tomcat classloaders... if you put xerces.jar version 1.0 (I'm taking that as example) into the WEB-INF/lib directory of your web application, then for that particular web application, version 1.0 of xerces is used, even though up in common/lib there might be a version 2.0 of xerces. And Tomcat will still use the one it knows about (the 2.0 one).

There should be no conflicts between jars used by your application and jars used by Tomcat, as long as they are kept in their proper places.
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a Tomcat 4.0.6 project I'm working on, the servlet seemed to use the xerces.jar in common.lib instead of the one in the applications lib. However, there is a not near the bottom of the release memo that says

--------------------------
Tomcat 4.0 and XML Parsers:
--------------------------
As described above, Tomcat 4.0 makes an XML parser (and many other standard
APIs) available to web applications. This parser is also used internally
to parse web.xml files and the server.xml configuration file. If you wish,
you may replace the "xerces.jar" file in "common/lib" with another XML parser,
as long as it is compatible with the JAXP/1.1 APIs.

Replacing common/lib/xerces.jar with the one we needed seems to be working for us.
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic