Implementing ClassLoader.getResource (String) without protocol handler

My classloader resolves resources for a source that does not have a url handler, for example, it gets resources from a database. This, of course, creates a problem for ClassLoader.getResource (String), which returns a URL. For working with URL.openConnection (), etc. I need a protocol handler that creates an additional problem. How can cna map the URL to the data provider without installing a special Url protocol handler, which requires me to set the system property at startup. The problem with url protocol handlers is that they are static and must be installed at startup, while my class loaders are dynamic and can come from many places.

Is there a way to solve this problem without using a protocol handler?

+4
source share
1 answer

Well, if you implement ClassLoader.getResource(String) , can you not use the constructor for the URL that takes the protocol handler as one of its arguments?

 public URL(String protocol, String host, int port, String file, URLStreamHandler handler) throws MalformedURLException 
+2
source

All Articles