Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Core Container

Reply
 
Thread Tools Display Modes
  #1  
Old Jul 20th, 2006, 05:21 PM
volenin volenin is offline
Junior Member
 
Join Date: Jan 2005
Posts: 22
Question Can WebApplicationContext load files from WEB-INF/lib/*.jar? classpath*: doesn't work

Hi,

I was wondering if WebApplicationContext can load resources (ie, applicationContext xml files) from inside jar files deployed in web application (under WEB-INF/lib directory)? I guess the answer is "application server specific" (because of ClassLoaders?..), but I was wondering if there is any override that can be made?..

My current web.xml looks like this:
Code:
<web-app>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      /WEB-INF/applicationContext-*.xml,
      classpath*:applicationContext-*.xml,
      classpath*:cihi/**/applicationContext.xml,
      classpath*:cihi/**/applicationContext-*.xml
    </param-value>
  </context-param>

...
</web-app>
This loads correctly all applicationContext files identified there, both from WEB-INF directory as well as from webapp classpath (WEB-INF/classes). This config however can NOT find any applicationContext files once they are packaged in jar file and placed under WEB-INF/lib.

My AS is OC4J 10.1.2.0.2, standalone version. I'm using Spring 1.2.6. Any ideas/suggestions?..

Thanks.

Vlad
Reply With Quote
  #2  
Old Jul 20th, 2006, 06:33 PM
Injecteer Injecteer is offline
Senior Member
 
Join Date: Dec 2005
Posts: 269
Default

not again!

try specifying the files explicitely, as classloaders do not like "*" in the path
Reply With Quote
  #3  
Old Jul 21st, 2006, 02:47 AM
Costin Leau's Avatar
Costin Leau Costin Leau is offline
Spring DM Lead
Spring Modules TeamSpring Team
 
Join Date: Jan 2005
Location: Bucharest, Romania
Posts: 5,106
Default

classpath* while powerful is restricted by the classloader.getResource() implementation. Some application servers behave correctly, others don't. To maximize the reuse across various platform, as Injecteer suggested, try to use a pattern as exact as possible without wildcard matching.
If you still depend on the classpath* for your environment then try using it with the WARs unpacked.
__________________
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
Please use [ c o d e ] [ / c o d e ] tags
Reply With Quote
  #4  
Old Jul 23rd, 2006, 12:56 PM
volenin volenin is offline
Junior Member
 
Join Date: Jan 2005
Posts: 22
Exclamation ... it doesn't seems like 100% ClassLoader issue...

For the record:

- the problem seems to be in a _webapplication_ class loader itself, ie, Tomcat loads resource from lib/jar files no problem, while OC4J - does not
- Java 1.4.2 system class loader has no problem loading resource by the path specified from the jar files
- the problem for JVM system classloader present only paths which _root starts_ with 'asteriks', ie: "classpath*:**/myres.xml" - in this case the classloader behaves as described in the docs
- a simple way to test whether your classloader hierarhy will support loaded resources from WEB-INF/lib JAR files or not is to check if you'll get an empty enumeration for the call: yourClassLoader.getResources("mypackage"), providing the jar file contains 'mypackage/**' directory hierarhy
- some debugging shows that the problem with OC4J seems to be that webapp classloader doesn't pass the request to the system classloader on one hand, and doesn't do proper traversing of JAR file on another hand

So, I believe normally there shouldn't be a problem loading resources from WEB-INF/lib jar files, but smth in OC4J prevents it.

That's why I actually wonder if it's worthwhile for Spring to have its own 'failover' ClassLoader to load resources, which would be a bit more 'cross platform' and doesn't rely that heavily on the underlying ClassLoader hierarhies...

Thanks for your advices - the exact path does work, though, again, from what I saw during debugging, the 'patterned' path should have worked as well...
Reply With Quote
  #5  
Old Jul 24th, 2006, 01:49 AM
Costin Leau's Avatar
Costin Leau Costin Leau is offline
Spring DM Lead
Spring Modules TeamSpring Team
 
Join Date: Jan 2005
Location: Bucharest, Romania
Posts: 5,106
Default

ClassLoaders are powerful but also dangerous. Inside a container is not even always an option - for example OC4j doesn't allow a custom classloader to be used to load your webapp.
You might want to check the oc4j forums - the internal classloader has a lot of features and forbidding getResources() might be one of them - probably you have to enable/activate it through some sort of configuration parameter.
Note that in this case, Spring still respects the contract - i.e. it calls the appropriate methods on the classloader who decides if it finds the resources or not.
__________________
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
Please use [ c o d e ] [ / c o d e ] tags
Reply With Quote
  #6  
Old Jul 24th, 2006, 12:31 PM
kstenerud kstenerud is offline
Junior Member
 
Join Date: Apr 2006
Posts: 3
Lightbulb

How about putting this little tidbit in the documentation somewhere, such as right after "4.7.2. The classpath*: prefix"

These little gotchas are the worst kind of showstopper because to anyone who hasn't been bitten by it yet, there appears to be no reason whatsoever why it shouldn't work.

I spent almost a week trying to figure out why the loader context could find my resources when deployed through jetty, but not through tomcat.
Reply With Quote
  #7  
Old Jul 24th, 2006, 03:45 PM
Costin Leau's Avatar
Costin Leau Costin Leau is offline
Spring DM Lead
Spring Modules TeamSpring Team
 
Join Date: Jan 2005
Location: Bucharest, Romania
Posts: 5,106
Default

I've raised a JIRA issue here - I'll try to address it in the upcoming feature:
http://opensource.atlassian.com/proj...rowse/SPR-2339
__________________
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
Please use [ c o d e ] [ / c o d e ] tags
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:08 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.