title: WildFly - getting resource from WAR
body: <p>I am using the following method to get a resource from WAR file in WildFly:</p>
  
  <pre><code>this.getClass().getResource(relativePath)
  </code></pre>
  
  <p>It works when the application is deployed as exploded WAR. <strong>It used to work</strong> with compressed WAR, too. Yesterday, I did a clean and rebuild of project in Eclipse, and it just stopped working.</p>
  
  <p>When I check the resource root:</p>
  
  <pre><code>logger.info(this.getClass().getResource("/").toExternalForm());
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>file:/C:/JBoss/wildfly8.1.0.CR1/modules/system/layers/base/org/jboss/as/ejb3/main/timers/
  </code></pre>
  
  <p>So, no wonder it doesn't work. It probably has something to do with JBoss module loading, but I don't know if this is a bug or normal behavior.</p>
  
  <p>I found various similar problems on StackOverflow, but no applicable solution. One of the suggestions is to use ServletContext like so:</p>
  
  <pre><code>@Resource
  private WebServiceContext wsContext;
  ...
  ServletContext servletContext = (ServletContext)this.wsContext.getMessageContext()
          .get(MessageContext.SERVLET_CONTEXT);
  servletContext.getResource(resourcePath);
  </code></pre>
  
  <p>But, when I try to obtain MessageContext in this manner, I get an IllegalStateException. So I am basically stuck. Any ideas?</p>