Sun GlassFish Enterprise Server 2.1 Troubleshooting Guide

Solution

Be sure to close streams opened by your applications. Also, if an application needs to be redeployed or undeployed repeatedly, and also needs to obtain a resource from a jar file using getResource or getResourceAsStream, consider using getClass().getResource which returns a URL object, then invoke the url.setUseCaches method to turn off caching for that jar file, and then use url.getInputStream() to obtain the stream.

Although turning off caching for accesses to the jar file can slow down performance, this approach does allow the application to be undeployed or redeployed. Note also that if the getClass().getResourceAsStream method is used instead, then the jar file in which the resource is located will be cached (this is the default Java runtime setting) and remain open until the server is stopped.