1

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")

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

So AS 7 has its URLStreamHandlerFactory allready set and this can be done only once.

Are there alternative ways to register a URLStreamHandler for the prefix classpath: on jboss or may I even get around with the vfs?

Community
  • 1
  • 1
Ralf Sigmund
  • 517
  • 1
  • 4
  • 13

1 Answers1

0

Very old thread, but I got some useful answer. As related by "David Lloyd" in JBoss issues:

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. 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.

Full details are here: https://issues.jboss.org/browse/AS7-1562

Well, in my case, I just change my implementation to use Spring's 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.

Reginaldo Santos
  • 840
  • 11
  • 24