Hi,

It is possible to specify the location of the OJB.properties file - see the
bottom of http://db.apache.org/ojb/docu/guides/ojb-properties.html for
details. Essentially, you can set a system property to specify the location
- but you can only have one value for that system property for the whole
JavaVM - i.e. you can't have two EAR's using two different OJB.properties
configuration files.

The other option (and this is very technical, and probably very naughty in
J2EE terms, and may be disallowed by your application server, use with
caution, etc, etc) would be to replace the contextClassLoader with your own
custom class loader that looks in a configurable location for resources
before delegating the orginal class loader. I've attached an example,
cribbed from code we use in our application (note : we don't actually use
this technique to configure OJB, but I see no reason why it shoudln't work).
You could then make the location a deployment parameter, or something, which
could be specified at deployment time. 

Just an idea.


Cheers,

Charles.

public class ExampleClassLoader {
  public static void main(String[] args) throws IOException {
    /* Essentially, we're replacing the class loader on this thread to allow
us to search our
       own locations for resources before delegating to the original class
loader. */

    // Do this in some initialisation class, before you initialise/refer-to
OJB
    ClassLoader originalClassLoader =
Thread.currentThread().getContextClassLoader();
    URL[] locationsToSearch = new URL[]{new URL("file:/C:/properties")};

    ResourceLocatorURLClassLoader cl = new
ResourceLocatorURLClassLoader(locationsToSearch, originalClassLoader);
    Thread.currentThread().setContextClassLoader(cl);

    //And here you would init OJB - instead, I'll do what OJB does
    URL url =
Thread.currentThread().getContextClassLoader().getResource("OJB.properties")
;
    Properties p = new Properties();
    p.load(url.openStream());
  }

  /**
   * This class loader ensures that the urlArray is searched *before* the
   * parent class loader is searched.
   */
  private static class ResourceLocatorURLClassLoader extends URLClassLoader
{
    public ResourceLocatorURLClassLoader(URL[] urlArray, ClassLoader
contextLoader) {
      super(urlArray, contextLoader);
    }

    public URL getResource(String name) {
      URL url = findResource(name);
      if (url == null) {
        url = super.getResource(name);
      }
      return url;
    }
  }

}

> -----Original Message-----
> From: Rick Banerjee [mailto:[EMAIL PROTECTED]
> Sent: 14 September 2004 10:58
> To: [EMAIL PROTECTED]
> Subject: Re: OJB fails during load testing
> 
> 
> Hi All, (special hello to Armin :-))
> 
> A Big Thanks To Armin & the OJB Team!
> 
> Sorry I didn't convey my gratitude earlier(had some
> issues with posting to the mailing list through the GMane site)
> 
> Well, we've made a lot of progress now! :-)
> here. Our app responds better to load testing now, we had
> some issues with setting up OJB properly because we were
> a bunch of newbies with only an idea that we wanted to use
> the coolest OR mapping tool out there :-)
> 
> Now, our road ahead has another obstacle. :-(
> 
> Our client has specified that OJB.properties has to be removed
> from within the EAR and then placed in a specific location.
> 
> So, my question is:
> 
> Can we put OJB.properties in say C:/Properties and still have
> OJB function properly?
> 
> If this is not possible, please do let me know why, because I
> have to convince the client to allow us to put in the OJB.properties
> file within the EAR.
> 
> Regards
> 
> Rick
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


___________________________________________________________
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to