Reading archived WebApp resources using getResource causes FileNotFoundException in EAP6

Solution Unverified - Updated -

Issue

  • While using the following JSP code in order to get the resource absolute path causes FileNotFoundException while reading the file:
<%
        java.net.URL url=getClass().getClassLoader().getResource("/my.xsd");
        java.net.URI uri = getClass().getClassLoader().getResource("/my.xsd").toURI();
        out.println("URI of my.xsd :: "+uri);
        out.println("Path of my.xsd :: "+getClass().getClassLoader().getResource("/my.xsd").getPath());
%>
  • Above code returns the following path which is not a valid path for reading resources and causes FileNotFoundException
URI of my.xsd  :: vfs:/content/TestApp.ear/TestWeb.war/WEB-INF/classes/my.xsd 
Path of my.xsd :: /content/TestApp.ear/TestWeb.war/WEB-INF/classes/my.xsd 
  • The XSD file is present inside the "/WEB-INF/classes/my.xsd" location of the Archived WAR file.

  • The above issue occurs only in case of Archived Applications whereas it returns proper path for the Exploded applications.

  • In JBoss EAP 6.1 the below line doesn't work and it is returning null.

URL ImageURL = this.getClass().getResource("/images/testIcon.png");

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content