Mark,

In general if there was a classloader from the thread and the class I would
pick one and try to load my resource. If I got nothing I would try the other
one. Something like:

ClassLoader  classLoader = Thread.currentThread().getContextClassLoader();
InputStream in = classLoader.getResourceAsStream();

if( in == null){
    classLoader = this.getClass().getClassLoader();
    in = classLoader.getResourceAsStream();
}

if( in == null)
    //all hope is lost...
else
    // do something cool.

Unfortunately this is the code in ClassFieldExtractorFactory:

            // use bytes to get a class 
            final ByteArrayClassLoader classLoader = 
                                                 new ByteArrayClassLoader(
Thread.currentThread().getContextClassLoader() );
            final Class newClass = classLoader.defineClass(
className.replace( '/', '.' ), bytes );

If I was writing this I would try to take the same approach as above. If
classLoader.defineClass threw an exception I would try to create a new
ByteArrayClassLoader with the parent defined as the classloader that loaded
ClassFieldExtractorFactory. I would have to think about how to get that
classLoader though since all this is occuring in a static method. 

I am not an expert on ClassLoaders so I will ask, does this make sense?
Nat








Mark Proctor-2 wrote:
> 
> http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java
> 
> This is how we determine the classloader:
> 
>     public PackageBuilderConfiguration() {
>         ClassLoader classLoader =
> Thread.currentThread().getContextClassLoader();
>         if ( classLoader == null ) {
>             classLoader = this.getClass().getClassLoader();
>         }
>         this.classLoader = classLoader;
>     }
> 
> I believe this is the normal way of doing it and to take it from the
> class, as default, may break other systems.
> 
> Mark
> 
> 
> 
> Nat wrote:
>> I finally found the problem. Drools has a ClassFieldExtractorFactory that
>> creates a classloader who's parent comes from
>> Thread.currentThread().getContextClassLoader(). This willl cause the
>> drools
>> classloader to not be able to see the plugin classes. A better way to do
>> it
>> would have been to check both the context and the current classes
>> classloader. Since that isn't going to happen I'll have to shift things
>> around a bit to make it work.
>>
>> Nat
>>
>>
>>
>> Edson Tirelli-3 wrote:
>>   
>>>    Nat,
>>>
>>>    What kind of environment are you working on? Stand-alone JSE, app 
>>> server JEE, etc?
>>>    I'm asking because yesterday I had to fix the same issue for a 
>>> JBRules Ant task and in the end it was an ant classloader that was 
>>> messing with some stuff jbrules needs.
>>>
>>>    So, basically, if you are sure you have all dependencies on 
>>> classpath, it is probably a classloader issue.
>>>
>>>    []s
>>>    Edson
>>>
>>>
>>> Nat wrote:
>>>
>>>     
>>>> At runtime I am getting a NoClassDefFound exception for the class
>>>> org.drools.base.BaseClassFieldExtractor when I try to call the method
>>>> addPackageFromDrl( src) from PackageBuilder. I know the class is in
>>>> drools-core.jar. I know that I can load and instansiate
>>>> org.drools.RuleBaseFactory which is in the same jar file so I know the
>>>> jar
>>>> is in my classpath. I'm guessing BaseClassFieldExtractor needs
>>>> something
>>>> that is missing???
>>>>
>>>> Does anyone have any ideas as to where I'm going wrong or how I can
>>>> find
>>>> what is missing?
>>>>
>>>> I know this is somewhat vague but I'm at a loss of where to look next.
>>>> Thanks in advance for your time,
>>>> Nat
>>>>  
>>>>
>>>>       
>>> -- 
>>>   ---
>>>   Edson Tirelli
>>>   Software Engineer - JBoss Rules Core Developer
>>>   Office: +55 11 3124-6000
>>>   Mobile: +55 11 9218-4151
>>>   JBoss, a division of Red Hat @ www.jboss.com
>>>
>>>   IT executives: Red Hat still #1 for value
>>>   http://www.redhat.com/promo/vendor/ 
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list please visit:
>>>
>>>     http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>>     
>>
>>   
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/NoClassDefFoundError%3A-org-drools-base-BaseClassFieldExtractor-tf2613781.html#a7297243
Sent from the drools - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to