You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Smith, Larry" <xl...@ti.com> on 2002/09/13 01:37:42 UTC

Various getResource() Approaches and Results

I've done some testing on various getResource(String) approaches.
The results are interesting:

Given the WEB Service located at:

	
"C:\jakarta-tomcat-4.0.4\webapps\axis\WEB-INF\classes\esda\SonarDie.class"

Attempts by this service to find the file "test.txt" return different
results depending on which getResource() approach is used (i.e. "test.txt"
has to be in different locations depending on which getResource() you use).

Here's the results:

      resURL = getClass.getClassLoader.getResource("test.txt");
and
      resURL =
MessageContext.getCurrentContext.getClassLoader.getResource("test.txt");

Both of the above approaches will find "test.txt" ONLY if it is in

	"C:/jakarta-tomcat-4.0.4/webapps/axis/WEB-INF/classes/".

They both return the URL

	"file:C:/jakarta-tomcat-4.0.4/webapps/axis/WEB-INF/classes/test.txt"

The following code will find "test.txt" ONLY if it is in

	"C:/jakarta-tomcat-4.0.4/webapps/axis/".

However, the URL it returns is missing a slash; it returns

	"jndi:/localhost/axistest.txt" instead of
"jndi:/localhost/axis/test.txt"

	URL resURL;

	ServletContext sc = ((HttpServlet)
 
mc.getProperty(HTTPConstants.MC_HTTP_SERVLET)).getServletContext();

	resURL = sc.getResource("test.txt");

Thanks & Regards,
Larry