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)
    • 8.x
    • 7.x
    • 6.x
    • 5.x
    • 4.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content