Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, should've been clearer, it's the standard web.xml file.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, is the file you're loading a Spring config file, because "contextConfigLocation" is a Spring configuration parameter.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't classpath:required-file.xml be enough? I mean, it's on the classpath, right?
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, okay; gotcha. Too bad!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic