views:

969

answers:

2

My first post, so go easy on me.

I'm looking for advice on organising and referencing third party jars for use in my j2ee web application. The jars I need to organise and reference are the JWSDP-2.0 JAXB api jars.

I'm using Eclipse and Tomcat 5.5. My web app exchanges XML with a web service, and therefore needs to do some XML marshalling and unmarshalling using the JAXB api's in JWSDP-2.0.

I've downloaded JWSDP-2.0 and installed to my PC. I'm now trying to figure out the best way to make the necessary jar files contained therein available to my web app within eclipse on my machine, and also within Tomcat both on my machine and the eventual test and production servers.

I started off just copying the .jar files to the WEB-INF/lib folder of my project. This meant the jar files would now be exported in the .war when deploying to Tomcat. However, I don't like this because the jar files come from a few different libraries in JWSDP-2.0, and copying them like this meant the were all just tossed in together, rather than nicely seperated as JAXB, JAXP, SAAJ etc. Also, there are some name clashes, eg, my web app already contains older xml parsing jars such as xalan.jar which are already used by a different part of the web app.

I then removed all these jars, and created a series of user libraries within eclipse, eg "jwsdp-2.0_jaxp", "jwsdp-2.0_jaxb" which reference the jars from their locations in the WSDP-2.0 instal. This works fine as far as compliing my web app in eclipse goes, but I now need to make these jars available to Tomcat and I'm a bit stuck there on the best way to do this.

So, at a basic level my question is how do I get jar files referenced in Tomcat?

More generally, I'm looking for some advice on best practice for referencing and including third party jars in a project with an eye to smooth deployment to servers.

If anybody can recommend any good articles/books/resorces on code organisation and deployment that would help me learn best practice for this sort of scenario that would be great

Cheers in advance.

+1  A: 

The best practice to organize your dependencies would be to use maven to build your eclipse project and war for tomcat and let him download all the dependencies required:

https://jaxb.dev.java.net/jaxb-maven2-plugin/

OMax
+3  A: 

A few points here:

  • If you have clashing JARS in your WAR file, then you're asking for trouble. You should sort out which ones your application needs, and discard the rest. otherwise, you run the risk of tomcat loading the "wrong" classes.
  • JWSDP 2.0 is very old, and contains an old, pre-release version of JAXB. I'd strongly recommend using the latest JAXB JARs (from http://jaxb.dev.java.net), since the early-access JAXB2 suffered from many problems.
  • While it might be nice for your WEB-INF/lib to have a structured directory layout, it doesn't really matter, since this is your build artifact. As long as you're sourcing the JARs from a structured repository, you shouldn't feel the need to retain that structure in the WAR. Tomcat doesn't care. The fact that you get name clashes by putting them all in one directory is a warning that you need to sort those clashes out.
skaffman