aspose file tools*
The moose likes JBoss/WildFly and the fly likes How do you read a resource from the root of an exploded webapp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "How do you read a resource from the root of an exploded webapp?" Watch "How do you read a resource from the root of an exploded webapp?" New topic
Author

How do you read a resource from the root of an exploded webapp?

Karsten Wutzke
Ranch Hand

Joined: Jul 20, 2010
Posts: 106

Hello,

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 (exploded and JAR) and deploy normally via 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...

Karsten

OCJP JavaSE 6 (86%)
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

The WEB-INF/classes directory, and the JARs in WEB-INF/lib, are in the classpath. If you want to access things within the WAR outside of that, use ServletContext.getRealPath()


JBoss In Action
Karsten Wutzke
Ranch Hand

Joined: Jul 20, 2010
Posts: 106

There was a coding error in my sources. The resource strings weren't prefixed with a slash - doh! It's working now.

Karsten
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

The resource strings weren't prefixed with a slash

That one always bites me too - I can never seem to remember when I need a slash and when I shouldn't use one. Glad you got it working.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you read a resource from the root of an exploded webapp?