Hi folks,
I'm using Spring's ApplicationContext.getResource() in order to retrieve some class files at application start-up and do stuff...
The code is very easy, I simply construct a query and passes it to the context, and iterate on the results :
This code is used in two different "contexts" :Code:String query = "classpath*:" + pkgBase + "/**/*.class"; logger.info("Scanning CLASSPATH entries : " + query); Resource[] resources; try { resources = springContext.getResources(query); } catch(IOException e) { ... } for (int i = 0; i < resources.length; i++) { ... }
1/ in a web app, using Spring Context Loader ;
2/ in a standalone Swing app, where I create the App Context myself.
1/ works fine : the resources are fetched when the .class are exploded (in WEB-INF/classes) and also when they're packaged (in a jar in WEB-INF/lib) ;
2/ doesn't work when .class are packaged in a jar : it only works if I have the .class files in a folder that's in my CLASSPATH... Since this app is a webstart, it's a pretty big issue :-/
As far as I see, only the way the Spring Application Context is created differs : in 1/ I have a WebApplicationContext created by the loader, in 2/ I do it myself by instanciating a ClassPathXmlApplicationContext...
I've been through the API docs :
http://static.springframework.org/sp...nResolver.html
And found a warning there :
As far as I understand it, this should not affect me (I always have a base package), but since I have this problem...WARNING: Note that "classpath*:" will only work reliably with at least one root directory before the pattern starts, unless the actual target files reside in the file system. This means that a pattern like "classpath*:*.xml" will not retrieve files from the root of jar files but rather only from the root of expanded directories.
Maybe I'm not using PathMatchingResourcePatternResolver when creating the ClassPathXmlCtx myself ?
Shall I use GenericAppCtx instead ?
Many thanks in advance for any information !
Have fun,
Remi


Reply With Quote
