Topic
  • 2 replies
  • Latest Post - ‏2013-09-06T14:43:36Z by Developer254
Developer254
Developer254
4 Posts

Pinned topic Java Operator Reference Jar file with embedded resource

‏2013-09-06T13:21:00Z |

I have a Streams Java Operator which references a Jar file. The Jar file has several param files embedded within. One of the classes in the Jar file loads in one of the param files using ClassLoader.getSystemResourceAsStrewam(PATH_TO_PARAM_FILE_RELATIVE_TO_BASE_OF_JAR);

This call returns null when executed in the Streams Environment. When executed from the cmd line the statement works fine.

Is this a known issue with Streams and if so is there a workaround?

Thanks.

  • Stan
    Stan
    76 Posts
    ACCEPTED ANSWER

    Re: Java Operator Reference Jar file with embedded resource

    ‏2013-09-06T14:29:47Z  

    I believe this article explains what you have encountered - Streams establishes a classloader heirarchy:

    http://www.coderanch.com/t/369908/java/java/ClassLoader-getSystemResourceAsStream

    Within Streams your code is running in a Child of the system classloader, your call is to the System Classload which cannot access the resources of the child.

    the article suggests using:   MyClass.class.getClassLoader().getResourceAsStream  instead.  Let me know if this works. 

  • Stan
    Stan
    76 Posts

    Re: Java Operator Reference Jar file with embedded resource

    ‏2013-09-06T14:29:47Z  

    I believe this article explains what you have encountered - Streams establishes a classloader heirarchy:

    http://www.coderanch.com/t/369908/java/java/ClassLoader-getSystemResourceAsStream

    Within Streams your code is running in a Child of the system classloader, your call is to the System Classload which cannot access the resources of the child.

    the article suggests using:   MyClass.class.getClassLoader().getResourceAsStream  instead.  Let me know if this works. 

  • Developer254
    Developer254
    4 Posts

    Re: Java Operator Reference Jar file with embedded resource

    ‏2013-09-06T14:43:36Z  
    • Stan
    • ‏2013-09-06T14:29:47Z

    I believe this article explains what you have encountered - Streams establishes a classloader heirarchy:

    http://www.coderanch.com/t/369908/java/java/ClassLoader-getSystemResourceAsStream

    Within Streams your code is running in a Child of the system classloader, your call is to the System Classload which cannot access the resources of the child.

    the article suggests using:   MyClass.class.getClassLoader().getResourceAsStream  instead.  Let me know if this works. 

    Exactly what I had feared. The Jar I am using is a 3rd party Jar file so I don't have the source to change but I will take this feedback and see if I can get the changes made. Thanks.