I have a localhost JBoss 6 setup with JBoss Tools and Eclipse doing the hot deploy of an exploded webapp. I used to launch my webapp via shell using main class with an explicit classpath and via JAR/WAR file. My resource loader used to work perfectly, but now since the webapp is on JBoss in an exploded directory structure with an "unknown" classpath, text file resources like "/db/jpql/whatever.jpql" aren't found (null is returned, leading to an NPE).
The question is:
How do you load resources from the root (or outside of the WEB-INF dir) of an exploded webapp (in JBoss)? I checked the classpath which is nothing but C:\dev\jboss\bin\run.jar...
I had "forgotten" to prefix my resource strings with a slash. Can't work reliably.
I had used
public static String readResource(String sResource)
{
String sContent = "";
InputStream is = null;
BufferedReader br = null;
try
{
is = TextFileLoader.class.getResourceAsStream(sResource);
// resource not found, check web environment
if ( is == null )
{
is = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream(sResource);
}
is.available();
br = new BufferedReader(new InputStreamReader(is));
...
}
...
}
to get the webapp resource if the current classes' classloader returned null.