Servlet can not access resources inside a jar file

I am running Weblogic 6.1 SP5 and I having problem accessing resources inside a jar file.

Okay, here is the problem: I have a servlet which uses some html/css/txt files that are inside a jar file. I packaged my WAR file in a way so that the jar file ends up inside the WEB-INF/lib directory. I tried to run my servlet but it says so and so file could not be found and gives 404 error.

I also created and EAR file and put the war file inside and put the required jar file inside META-INF/lib directory and put a classpath entry in the Manifest.mf file inside META-INF , BUT still no luck. Any suggestions please?

However, I extracted the contents of the jar file to the DefaultWebapp directory and it worked. But can anyone tell me why my servlet can not access the contents inside a jar file? Any suggestions please?

Thanks.

[856 byte] By [edmda] at [2007-10-1 1:20:24]
# 1

> But can anyone tell me why my servlet can not access the

> contents inside a jar file? Any suggestions please?

> Thanks.

Without seeing your code, it is likely that you are trying to use file names (like /some/path/yourFileName.ext), not resource names (loadable from the class loader) like /yourFileName.ext.

Example:

Instead of:

FileInputStream stream = new FileInputStream("/some/path/yourFileName.ext");

do this:

InputStream stream = getClass().getResourceAsStream("/yourFileName.ext");

There are other API's which take either a string file name or a URL. You want to go the URL way, where the URL is taken from the classpath as:

URL url = getClass().getResource("/yourFileName.ext");

warnerjaa at 2007-7-8 1:38:13 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks for your reply. You opened my eye.In fact, I was just re-using the existing jsp/servlets (compay) codes and did not pay much attention on how the recources were being accessed. Looks like the code is not using classloaders. That explains. Thanks
edmda at 2007-7-8 1:38:13 > top of Java-index,Java Essentials,Java Programming...