You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by "skip@theDevers" <sk...@thedevers.org> on 2007/09/29 03:11:50 UTC

In case anyone is interested

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


Re: In case anyone is interested

Posted by Jacques Le Roux <ja...@les7arts.com>.
Skip,

Thanks for comment, definitively in my notes :o)

Jacques

De : "skip@theDevers" <sk...@thedevers.org>
> Jacques
>
> That is exactly what I did, I added a -soe (and soe.properties, etc) and my
> own container, almost identical to the XUIContainer.  However, this was a
> pure java app and when the GUI thread had control I could not call any Ofbiz
> services because of the class not found error.
>
> Didnt have a problem when called from the container thread, only when called
> by the GUI thread.
>
> Skip
>
> -----Original Message-----
> From: Jacques Le Roux [mailto:jacques.le.roux@les7arts.com]
> Sent: Saturday, September 29, 2007 2:01 PM
> To: user@ofbiz.apache.org
> Subject: Re: In case anyone is interested
>
>
> Thanks Skip
>
> Put in my notes, maybe useful later. Not sure there is not a better practice
> for that, though. Like using something similar than
> the -pos parameter in command line ?
>
> Jacques
>
> ----- Message d'origine -----
> De : "skip@theDevers" <sk...@thedevers.org>
> À : <us...@ofbiz.apache.org>
> Envoyé : samedi 29 septembre 2007 03:11
> Objet : In case anyone is interested
>
>
> > 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
> >
>
>


RE: In case anyone is interested

Posted by "skip@theDevers" <sk...@thedevers.org>.
Jacques

That is exactly what I did, I added a -soe (and soe.properties, etc) and my
own container, almost identical to the XUIContainer.  However, this was a
pure java app and when the GUI thread had control I could not call any Ofbiz
services because of the class not found error.

Didnt have a problem when called from the container thread, only when called
by the GUI thread.

Skip

-----Original Message-----
From: Jacques Le Roux [mailto:jacques.le.roux@les7arts.com]
Sent: Saturday, September 29, 2007 2:01 PM
To: user@ofbiz.apache.org
Subject: Re: In case anyone is interested


Thanks Skip

Put in my notes, maybe useful later. Not sure there is not a better practice
for that, though. Like using something similar than
the -pos parameter in command line ?

Jacques

----- Message d'origine -----
De : "skip@theDevers" <sk...@thedevers.org>
À : <us...@ofbiz.apache.org>
Envoyé : samedi 29 septembre 2007 03:11
Objet : In case anyone is interested


> 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
>



Re: In case anyone is interested

Posted by Jacques Le Roux <ja...@les7arts.com>.
Thanks Skip

Put in my notes, maybe useful later. Not sure there is not a better practice for that, though. Like using something similar than
the -pos parameter in command line ?

Jacques

----- Message d'origine ----- 
De : "skip@theDevers" <sk...@thedevers.org>
À : <us...@ofbiz.apache.org>
Envoyé : samedi 29 septembre 2007 03:11
Objet : In case anyone is interested


> 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
>