You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Ilkka Priha <im...@surfeu.fi> on 2005/03/04 08:32:47 UTC

OJB.properties may lock web app jars

Hello,

Currently, OJB loads the OJB.properties file by getting an input stream from the 
corresponding URL. However, if the properties file is embedded in a jar archive, 
this method locks the corresponding jar and prevents it from being removed 
during undeployment of a web application (at least in Sun jdk under Windows). 
Some web containers (e.g. Tomcat) have non-standard configuration options to 
handle jar resources in a specific way to prevent locking, but a more general 
solution is to disable caching in the URL connection before opening the input 
stream. The corresponding patch is attached below.

Another solution would be to apply the ClassLoader.getResourceAsStream() method 
instead of the ClassLoader.getResource() method currently provided by 
ClassHelper. This would allow the class loader to provide a non-locking stream.

LoggingConfiguration applies the latter by getting the class loader from 
ClassHelper and calling directly its getResourceAsStream() method.

-- Ilkka


RCS file: 
/home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/Attic/ConfigurationAbstractImpl.java,v
retrieving revision 1.15
diff -u -r1.15 ConfigurationAbstractImpl.java
--- ConfigurationAbstractImpl.java	16 Jun 2004 20:34:22 -0000	1.15
+++ ConfigurationAbstractImpl.java	4 Mar 2005 07:16:45 -0000
@@ -25,6 +25,7 @@
  import java.io.FileNotFoundException;
  import java.io.InputStream;
  import java.net.URL;
+import java.net.URLConnection;
  import java.util.Properties;
  import java.util.StringTokenizer;

@@ -426,7 +427,10 @@

              logger.info("Loading OJB's properties from file " + url);

-            InputStream strIn = url.openStream();
+            URLConnection conn = url.openConnection();
+            conn.setUseCaches(false);
+            conn.connect();
+            InputStream strIn = conn.getInputStream();

              properties.load(strIn);
              strIn.close();




---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: OJB.properties may lock web app jars

Posted by Brian McCallister <br...@apache.org>.
Checked into OJB_1_0_RELEASE only, as ConfigurtionAbstractImpl doesn't  
exist in HEAD anymore. Should be in 1.0.2 in a couple days.

Thank You!

-Brian

On Mar 4, 2005, at 2:32 AM, Ilkka Priha wrote:

> Hello,
>
> Currently, OJB loads the OJB.properties file by getting an input  
> stream from the corresponding URL. However, if the properties file is  
> embedded in a jar archive, this method locks the corresponding jar and  
> prevents it from being removed during undeployment of a web  
> application (at least in Sun jdk under Windows). Some web containers  
> (e.g. Tomcat) have non-standard configuration options to handle jar  
> resources in a specific way to prevent locking, but a more general  
> solution is to disable caching in the URL connection before opening  
> the input stream. The corresponding patch is attached below.
>
> Another solution would be to apply the  
> ClassLoader.getResourceAsStream() method instead of the  
> ClassLoader.getResource() method currently provided by ClassHelper.  
> This would allow the class loader to provide a non-locking stream.
>
> LoggingConfiguration applies the latter by getting the class loader  
> from ClassHelper and calling directly its getResourceAsStream()  
> method.
>
> -- Ilkka
>
>
> RCS file:  
> /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/util/ 
> configuration/impl/Attic/ConfigurationAbstractImpl.java,v
> retrieving revision 1.15
> diff -u -r1.15 ConfigurationAbstractImpl.java
> --- ConfigurationAbstractImpl.java	16 Jun 2004 20:34:22 -0000	1.15
> +++ ConfigurationAbstractImpl.java	4 Mar 2005 07:16:45 -0000
> @@ -25,6 +25,7 @@
>  import java.io.FileNotFoundException;
>  import java.io.InputStream;
>  import java.net.URL;
> +import java.net.URLConnection;
>  import java.util.Properties;
>  import java.util.StringTokenizer;
>
> @@ -426,7 +427,10 @@
>
>              logger.info("Loading OJB's properties from file " + url);
>
> -            InputStream strIn = url.openStream();
> +            URLConnection conn = url.openConnection();
> +            conn.setUseCaches(false);
> +            conn.connect();
> +            InputStream strIn = conn.getInputStream();
>
>              properties.load(strIn);
>              strIn.close();
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org