[jboss-user] [Tomcat, HTTPD, Servlets & JSP] - classloader and resources.

tgiaccone do-not-reply at jboss.com
Wed Dec 10 16:06:23 EST 2008

This is my first posting to the JBOSS community forums, if I've picked the wrong topic to post this to, I apologize and please point me to the correct location.

My problem:

I have a utility project for the servlet I'm developing. The artifact produced by this project is a jar file.  The jar file gets included in the lib directory of the servlet as part of the war file creation.  I  have verified that this jar file is in the WEB-INF/lib directory.  

In that jar file, I have a number of BIRT report design files. These are files that contain XML that describes a report layout. Each file ends with the extension .rptdesign  

If I unarchive the jar file, I end up with three top level directories:


The com hierarchy contains the .class files the birtReport directory contains my birt report templates. 

I want to be able to retrieve these xml files in my servlet.  To do that I execute the following code:

anonymous wrote : 
  | String name="birtReports/myReport.rptdesign";
  | InputStream ips = this.getClass().getClassLoader().getResourceAsStream(name))

The result of this is that ips == null. 

In an attempt to debug this problem. I added to the jar file, another entry, that creates a file "simple.properties" at the same level as the com and birtReports directories. So now on extraction of the jar into a temp directory I end up with:

ls -1

If I change the above code to look like this:
anonymous wrote : 
  | name="simple.properties";
  | InputStream ips = this.getClass().getClassLoader().getResourceAsStream(name))
after executing ips is non-null and I can read from the inputstream to get the contents of the file. 

Can someone explain to me, what I'm doing incorrectly?  In addition, when reading the documentation on resources, I understand that in some situations you would want to pre-pend a "/" to the resource that you're trying to extract. It's not clear to me where that "root" location is. Can someone explain the use of that "/" for me? 

Thanks in advance, 

Tony Giaccone

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4195734#4195734

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4195734

More information about the jboss-user mailing list