Search code examples
javajakarta-eeejb-3.1wildfly-8java-ee-7

Wildfly (8.2.final): How to read a classpath resource?


I have a property file in the classpath of my application.

src/main/resources/default.properties

In an ejb, it has singleton and startup annotations, I try to read the file as following

Thread.currentThead().getContextLoader().getResource("default.properties");

This doesn't work. Works in Glassfish though.

Is there any way to read classpath resource in wildfly?


Solution

  • I found the solution.

    The call

    Thread.currentThead().getContextLoader().getResource("default.properties");
    

    Doesn't work, but the following works.

    InputStream is = Thread.currentThread ().getContextClassLoader ()
                    .getResourceAsStream ( "default.properties" );
    

    I don't know why it is so, but may be this will help.