PDA

View Full Version : Class loader issue


spring_field
Nov 7th, 2007, 03:06 PM
I"m getting the familiar "Root context not WebApplicationContext" exception. Several threads say this is due to the same jar present multiple times. The jar in question is spring.jar. I'm using Tomcat 6.0 and Spring RC 2.5 (and Webflow 2.0 Dev release) (chancy?)

When I put spring.jar in the <CATALINA_HOME>/lib and in /WEB-INF/lib I get the "not WebApplicationContext" exception.

With the jar in <CAT_HOME>/lib and not in /WEB-INF/lib I
fail to instantiate org.springframework.orm.hibernate3.annnotation.
AnnotationSessionFactoryBean, class not found.

With the jar in /WEB-INF/lib and not in <CAT_HOME>/lib I get java.lang.NoClassDefFoundError: org/springframework/context/ApplicationListener

Why is having the jar in both <CAT_HOME>/lib and /WEB-INF/lib an issue? Tomcat 6.0 doc says the class loaders for these areas don't see each other. Thanks.

spring_field
Nov 7th, 2007, 03:20 PM
Actually the Tomcat doc says the /WEB-INF/lib jars are invisible to other webapps, not invisible to the container itself. So there is a duplicate class issue. On the other hand if the class loader for the webapp delegates sooner rather than later (after first looking in its areas) why does the behavior suggest the jar is not visible from the webapp itself? The Tomcat container and the webapp both need the jar, and both should have it, even though the container loads it, given the webapp loader behavior. The app builds okay when the jar is in <CAT_HOME>/lib and not in WEB-INF/lib. But won't run.

lumpynose
Nov 7th, 2007, 04:54 PM
I've never put anything in the tomcat directories, everything goes in WEB-INF. I don't understand what you mean by "The app builds okay when the jar is in <CAT_HOME>/lib and not in WEB-INF/lib." Do you have <CATALINA_HOME>/lib in your classpath? The only file I add from there to my classpath is servlet-api.jar.

spring_field
Nov 7th, 2007, 05:12 PM
Don't you want the jars as high up as possible, to make the war smaller for redistribution, or support other apps on the same server? The /WEB-INF/libs don't see each other. I suppose there could be version problems if all the apps use the same framework jars but it's not a problem in this case.

I'm making slow progress sorting this out, I think. I was switching betw TC 5.5 and 6.0, and with Faces and without to test things and the lib dirs got out of whack.

lumpynose
Nov 7th, 2007, 05:19 PM
Dude, you're still living in the 20th century. This is the age of 500 gig disks.

Ok, do yourself a favor and stop screwing around with <CATALINA_HOME>/lib and get it to work with only WEB-INF/lib. It's not worth it in the long run to put things in <CATALINA_HOME>/lib; you'll just end up wasting a lot of time, like you are now, trying to get things working.

Edit: and just to be safe; wipe your tomcat installation and reinstall so that you're sure it's clean.

spring_field
Nov 8th, 2007, 09:28 AM
There's something to be said for sending a 250K war as an email attachment rather than posting a NN meg war for FTP (and sending an email), esp when 97% of the big war changes only for framework versions.

Jörg Heinicke
Nov 8th, 2007, 11:13 PM
There are valid or even compelling reasons to make Spring jars accessible via the common classloader (of whatever application/ servlet container). You only must take care then to NOT add Spring jars to both the web application and the common classloader as this leads to ClassCastExceptions.

In your case you only seem to move Spring jars to common classloader but not their dependencies. Look on which classes it is actually failing. My guess for AnnotationSessionFactoryBean would be Hibernate classes, so add Hibernate to common classloader as well. Or even dependencies of Hibernate.

Joerg