Yesterday, I sent out this email:

Stumped on a complicated question:

I am getting the following error:

java.lang.ClassNotFoundException:
org.ofbiz.service.engine.StandardJavaEngine

On this line 81 of
org.ofbiz.service.engine.GenericEngineFactory.getGenericEngine:

  Class c = loader.loadClass(className);


I am running ofbiz as a standalone app, similiar to java ofbiz.jar -pos


I have solved the problem and the solution was fairly simple.  I was
prepared to do a reflection call to addURL on the ClassLoader, but the the
solution turned out to be even simpler than that.

When Ofbiz instantiated my container, I simply grabbed the class loader it
used to start me up and then passed it to the Ofbiz connection layer like
this:

ClassLoader loader = Thread.currentThread().getContextClassLoader();
if(loader instanceof URLClassLoader)
{
        URLClassLoader urlLoader = (URLClassLoader)loader;
        connection.setClassLoader (urlLoader);

}


In the connection layer, I have this code:

void resetClassLoader()
{
        if(this.loader == null)
                return;

        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if(loader != this.loader)
        Thread.currentThread().setContextClassLoader(this.loader);

}

I then simply call resetClassLoader() every time before I call an Ofbiz
service.

Works a charm.

Skip

Reply via email to