I am using Java-EE (Wildfly v.17)
I want to access the file "config.txt" which resides within WEB-INF/classes/config.txt
.
I know one solution with servletContext
.
However, I am wondering why something common does NOT work:
// prints: file:/Users/test/server/wildfly-17.0.1.Final/modules/system/layers/base/org/jboss/as/ejb3/main/timers/
// why does this point to "ejb3/main/timers" ???
log.info(User.class.getResource("/").toExternalForm());
Nothing of those works, I always get java.lang.NullPointerException
(no file found, but the file is there!)
var resource = User.class.getResource("/config.txt");
var resource = User.class.getResource("/WEB-INF/classes/config.txt")
var resource = User.class.getResource("config.txt")
var resource = getClass().getResource("config.txt")
var resource = Thread.currentThread().getContextClassLoader().getResource("config.txt")
How can I use getResource()
or getResourceAsStream()
within Wildfly?
(Or where should I put the config.txt
to be able to use getResource()
?)