aspose file tools*
The moose likes Servlets and the fly likes Loading a ServletContext resource that is inside a JAR that is inside my WAR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Loading a ServletContext resource that is inside a JAR that is inside my WAR" Watch "Loading a ServletContext resource that is inside a JAR that is inside my WAR" New topic
Author

Loading a ServletContext resource that is inside a JAR that is inside my WAR

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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

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: 3274
    
    5

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

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: 3274
    
    5

Sorry, should've been clearer, it's the standard web.xml file.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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: 3274
    
    5

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

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: 3274
    
    5

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

Oh, okay; gotcha. Too bad!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading a ServletContext resource that is inside a JAR that is inside my WAR