0

I am having the same problem in JBoss but not in GlassFish as mentioned here in an earlier question.

classLoader.getResource doesn't work in jar file

But my problem is that I can not use getResourceAsStream(). It returns a stream object and I need a URL object as returned by getResource(). I am using that URL in a quite huge product. If I use stream I have to make a very big change.

Is there any way to get a URL instead of a stream?

Community
  • 1
  • 1
Daim
  • 57
  • 1
  • 9
  • Are you using URL.getFile() like that question is using? URL.getFile() *does not* convert a URL into a valid file path. It merely returns the path portion of the URL. (In the days of Java 1.0, most URLs referred to physical files, whether on the same system or on another system; that is why the method is named getFile.) Do not attempt to convert your URL to a file. – VGR Mar 01 '17 at 16:42
  • @VGR no i am not using URL.getFile() but i am passing the URL object to a parser function. getResource() works fine but it doesnt work with Jboss. There is an alternative function getResourceAsStream() which was a suggestion in the answer of previous question but in my case I need URL not stream. – Daim Mar 01 '17 at 22:09
  • What exactly is the problem? How can you tell that the resource URL doesn’t work? – VGR Mar 02 '17 at 03:16
  • classLoader.getResource(name) returns null. – Daim Mar 02 '17 at 07:59
  • Are you saying that passing the same name to `getResourceAsStream` does not return null? That seems unlikely. What is the value of `name`? – VGR Mar 02 '17 at 14:34
  • No I didnt test getResourceAsStream() but it was in the answer of the question which I mentioned as a reference in my question. Anyways I have found a solution. The problem seems to be with the classLoader(). If I get classLoader from ClassName.class.getClassLoader().getResource(name); it returns null but if I use another ClassLoader Thread.currentThread().getContextClassLoader().getResource(name); it works fine. – Daim Mar 02 '17 at 15:42

0 Answers0