How to get resources via the ClassLoader in a JavaEE application in JBoss EAP

Solution Unverified - Updated -

Issue

  • We are converting from weblogic to JBoss. We have some typical code that loads an xml file using
InputStream is = getClass().getResourceAsStream(FILENAME);

This works fine in one class. In another class we use

InputStream is = Class.class.getResourceAsStream(FILENAME); 

Because that class is a singleton and is set up with static methods so getClass() won't work. We also tried Classloader.getResourceAsStream(FILENAME) but that didn't work either. When then switched the class to be non-static and it works too. Is there a way to get the classloaders to work properly with a static method?

Environment

  • JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 5.x
    • 4.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.