Author
Loading a ServletContext resource that is inside a JAR that is inside my WAR
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
Hi all,
I'm trying to get the right syntax for my web.xml file to reference a file that is inside my JAR file which in turn is inside the WEB-INF/lib directory of my WAR file. e.g.
Structure
Attempt 1 web.xml
Attempt 2 web.xml
When tomcat loads the WAR file both attempts fail, e.g.
Any ideas where I'm going wrong? Is this even possible?
Cheers, Martijn - Blog ,
Twitter , PCGen , Ikasan , My The Well-Grounded Java Developer book! ,
My start-up .
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Aug 12, 2010 06:03:55
0
I wasn't even aware something like this was possible; is there a documentation reference you could provide? You could *try* using a classpath:etc. style reference, but I think that depends on the parameter consumer knowing how to handle that--although I'm not really sure how that functionality is implemented, if it's generic to Java or just a Spring thing, and so on :/
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
Hi David,
There's no documentation that I've been able to find unfortunately . If I have the resource outside of the JAR I can reference it just fine e.g.
But I'd rather keep the configuration in the JAR file (so I can use it in my integration tests without firing up a web-container).
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Aug 12, 2010 06:21:10
0
Is this a Spring config file? If so, use their classpath syntax. If *you* are loading the file, how are you doing so?
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
Sorry, should've been clearer, it's the standard web.xml file.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Aug 12, 2010 06:24:35
0
No, is the file you're loading a Spring config file, because "contextConfigLocation" is a Spring configuration parameter.
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
A yes sorry you're completely right.
So I've now also tried:
and
But I still get the same error message, I'm sure I've just got a silly typo somewhere...
Ah, no actually there's a bug in Spring fixed in 3.0.3, see:
http://slava-technical.blogspot.com/2010/06/spring-classpath-resource-resolving.html
That's a little irritating since I'm stuck on Spring 2.5.6 for now!
Thanks for your help David!!
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Aug 12, 2010 07:05:29
0
Shouldn't classpath:required-file.xml be enough? I mean, it's on the classpath, right?
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
As far as I can tell from my experiments no , as the actual resource is inside a JAR file Spring has a bug which means that retrieval fails.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Aug 12, 2010 07:11:48
0
Oh, okay; gotcha. Too bad!
subject: Loading a ServletContext resource that is inside a JAR that is inside my WAR