[英]load URL Resources from the Classpath on JBoss AS 7
URL to load resources from the classpath in Java describes how to use a URLStreamHandler
for enabling url-paths like new URL("classpath:org/my/package/resource.extension")
从Java中的类路径加载资源的URL描述了如何使用
URLStreamHandler
来启用new URL("classpath:org/my/package/resource.extension")
路径new URL("classpath:org/my/package/resource.extension")
I would like to use the same Approach on JBoss AS 7, but calling java.net.URL.setURLStreamHandlerFactory(URL.java:1102)
results in java.lang.Error: factory already defined
我想在JBoss AS 7上使用相同的方法,但是调用
java.net.URL.setURLStreamHandlerFactory(URL.java:1102)
导致java.lang.Error: factory already defined
So AS 7 has its URLStreamHandlerFactory
allready set and this can be done only once. 因此,AS 7的
URLStreamHandlerFactory
已全部设置好,并且只能执行一次。
Are there alternative ways to register a URLStreamHandler
for the prefix classpath:
on jboss or may I even get around with the vfs
? 是否有其他方法可以在jboss上为前缀
classpath:
注册URLStreamHandler
,或者我甚至可以避开vfs
?
Very old thread, but I got some useful answer. 线程很旧,但是我得到了一些有用的答案。 As related by "David Lloyd" in JBoss issues:
正如JBoss问题中的“ David Lloyd”所描述的:
In AS7, this is just a question of calling org.jboss.modules.Module#registerURLStreamHandlerFactoryModule() with the name of the module containing the handler factory for your protocol, and ensuring that that module has a META-INF/services/java.net.URLStreamHandler file in it.
在AS7中,这只是一个调用org.jboss.modules.Module#registerURLStreamHandlerFactoryModule()的问题,该模块的名称包含协议的处理程序工厂,并确保该模块具有META-INF / services / java。 net.URLStreamHandler文件在其中。 Alternatively, you can specify the module name in the jboss.protocol.handler.modules system property, which works similarly to java.protocol.handler.pkgs except rather than accepting a list of package names from the application class path, it accepts a list of module names from the boot module loader.
另外,您可以在jboss.protocol.handler.modules系统属性中指定模块名称,该属性与java.protocol.handler.pkgs相似,除了从应用程序类路径接受包名称列表之外,它接受一个列表引导模块加载器中的模块名称。
Full details are here: https://issues.jboss.org/browse/AS7-1562 完整细节在这里: https : //issues.jboss.org/browse/AS7-1562
Well, in my case, I just change my implementation to use Spring's PathMatchingResourcePatternResolver: 好吧,就我而言,我只是将实现更改为使用Spring的PathMatchingResourcePatternResolver:
ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
try {
Resource [] mappingLocations = patternResolver.getResources("classpath*:" + myBaseXmlPath + "/**/*.xml");
for(int i = 0; i < mappingLocations.length; i++) {
// do whatever you want ...
System.out.println(mappingLocations[i].getFile());
}
}
catch(IOException e) {
throw new RuntimeException(e);
}
It already deals with 'vfs' by proxing the classloader. 它已经通过继承类加载器来处理“ vfs”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.