You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by "Millies, Sebastian" <Se...@softwareag.com> on 2011/12/07 16:27:59 UTC

Contributions and Runtime Classpath

Hello there,

I am having a class loading problem, and want to make sure that I understand
what a contribution is.

My setup is as follows: At some point I want my SCA code to dynamically load
classes (customer-specific stuff provided by the customer at deployment time).
For that purpose, jar-files are put in some extensions directory, and are loaded
when the node starts:

   File extensionsDir = new File( "extensions" );
    if( extensionsDir.exists() && extensionsDir.isDirectory() && extensionsDir.canRead() ) {
      for( File extension : extensionsDir.listFiles( EXTENSIONS_FILTER ) ) {
        URL contribURL = extension.toURI().toURL();
        contributions.add( new SCAContribution( contribURL.toExternalForm(), contribURL.toExternalForm() ) );
      }
    }

…
    SCANode node = factory.createSCANode( compositeURI,
                                          contributions.toArray( new SCAContribution[contributions.size()] ) );

When the node starts, one sees  the jars being loaded:
INFO: Loading contribution: file:/D:/foo/extensions/myclasses.jar

Is this not sufficient to make these classes available on the runtime classpath?
When I do
  Thread.currentThread().getContextClassLoader().loadClass(className)

I get a ClassNotFoundException. What may I be overlooking?


n  Sebastian
IDS Scheer Consulting GmbH
Geschäftsführer/Managing Directors: Kamyar Niroumand, Ivo Totev
Sitz/Registered office: Altenkesseler Straße 17, 66115 Saarbrücken, Germany - Registergericht/Commercial register: Saarbrücken HRB 19681
http://www.softwareag.com


Re: Contributions and Runtime Classpath

Posted by Simon Nash <na...@apache.org>.
Simon Nash wrote:
> Millies, Sebastian wrote:
>> Hello there,
>>
>>  
>>
>> I am having a class loading problem, and want to make sure that I 
>> understand
>>
>> what a contribution is.
>>
>>  
>>
>> My setup is as follows: At some point I want my SCA code to 
>> dynamically load
>>
>> classes (customer-specific stuff provided by the customer at 
>> deployment time).
>>
>> For that purpose, jar-files are put in some extensions directory, and 
>> are loaded
>>
>> when the node starts:
>>
>>  
>>
>>    File extensionsDir = new File( "extensions" );
>>
>>     if( extensionsDir.exists() && extensionsDir.isDirectory() && 
>> extensionsDir.canRead() ) {
>>
>>       for( File extension : extensionsDir.listFiles( EXTENSIONS_FILTER 
>> ) ) {
>>
>>         URL contribURL = extension.toURI().toURL();
>>
>>         contributions.add( new SCAContribution( 
>> contribURL.toExternalForm(), contribURL.toExternalForm() ) );
>>
>>       }
>>
>>     }
>>
>>  
>>
>> …
>>
>>     SCANode node = factory.createSCANode( compositeURI,
>>
>>                                           contributions.toArray( new 
>> SCAContribution[contributions.size()] ) );
>>
>>  
>>
>> When the node starts, one sees  the jars being loaded:
>>
>> INFO: Loading contribution: file:/D:/foo/extensions/myclasses.jar
>>
>>  
>>
>> Is this not sufficient to make these classes available on the runtime 
>> classpath?
>>
>> When I do
>>
>>   Thread.currentThread().getContextClassLoader().loadClass(className)
>>
>>  
>>
>> I get a ClassNotFoundException. What may I be overlooking?
>>
> Tuscany uses contribution classloaders for loading code from contributions.
> To get classes loaded by these classloaders, you need to use the SCA
> contribution import/export mechanism.
> 
> It is possible to set things up so that code is loadable by a contribution
> classloader as well as by the thread context classloader and/or the system
> classloader that Java uses to start the application.  However this can
> cause problems with contribution import/export not working properly,
> so this setup isn't a good idea IMO.
> 
> I prefer to set things up with the contribution classloaders separate from
> the system classloader and thread context classloader.  You can see some
> examples of this setup in the travel sample--look at the Introducing
> scenario which bootstraps by loading three contributions in the launcher,
> then hands control to one of them.  All the classes in these contributions
> aren't present on the Java system classpath and aren't loaded by the
> thread context classloader.
> 
> Can you say more about why you are trying to load contribution classes
> using the thread context classloader?
> 
>   Simon
 >
Some further thoughts on this: perhaps the issue is that you don't know
the Java packages of the customer classes and therefore can't list these
classes in export and import statements.  If so, I don't think you will
be able to use contributions to load these classes.  However, if you do
know the package names then I think you should probably be able to make
this work using contributions if you set things up correctly.

   Simon

>>  
>>
>> n  Sebastian
>>
>> IDS Scheer Consulting GmbH
>> Geschäftsführer/Managing Directors: Kamyar Niroumand, Ivo Totev
>> Sitz/Registered office: Altenkesseler Straße 17, 66115 Saarbrücken, 
>> Germany - Registergericht/Commercial register: Saarbrücken HRB 19681
>> *http://www.softwareag.com*
>>
> 
> 
> 


Re: Contributions and Runtime Classpath

Posted by Simon Nash <na...@apache.org>.
Millies, Sebastian wrote:
> Hello there,
> 
>  
> 
> I am having a class loading problem, and want to make sure that I understand
> 
> what a contribution is.
> 
>  
> 
> My setup is as follows: At some point I want my SCA code to dynamically load
> 
> classes (customer-specific stuff provided by the customer at deployment 
> time).
> 
> For that purpose, jar-files are put in some extensions directory, and 
> are loaded
> 
> when the node starts:
> 
>  
> 
>    File extensionsDir = new File( "extensions" );
> 
>     if( extensionsDir.exists() && extensionsDir.isDirectory() && 
> extensionsDir.canRead() ) {
> 
>       for( File extension : extensionsDir.listFiles( EXTENSIONS_FILTER ) ) {
> 
>         URL contribURL = extension.toURI().toURL();
> 
>         contributions.add( new SCAContribution( 
> contribURL.toExternalForm(), contribURL.toExternalForm() ) );
> 
>       }
> 
>     }
> 
>  
> 
> …
> 
>     SCANode node = factory.createSCANode( compositeURI,
> 
>                                           contributions.toArray( new 
> SCAContribution[contributions.size()] ) );
> 
>  
> 
> When the node starts, one sees  the jars being loaded:
> 
> INFO: Loading contribution: file:/D:/foo/extensions/myclasses.jar
> 
>  
> 
> Is this not sufficient to make these classes available on the runtime 
> classpath?
> 
> When I do
> 
>   Thread.currentThread().getContextClassLoader().loadClass(className)
> 
>  
> 
> I get a ClassNotFoundException. What may I be overlooking?
> 
Tuscany uses contribution classloaders for loading code from contributions.
To get classes loaded by these classloaders, you need to use the SCA
contribution import/export mechanism.

It is possible to set things up so that code is loadable by a contribution
classloader as well as by the thread context classloader and/or the system
classloader that Java uses to start the application.  However this can
cause problems with contribution import/export not working properly,
so this setup isn't a good idea IMO.

I prefer to set things up with the contribution classloaders separate from
the system classloader and thread context classloader.  You can see some
examples of this setup in the travel sample--look at the Introducing
scenario which bootstraps by loading three contributions in the launcher,
then hands control to one of them.  All the classes in these contributions
aren't present on the Java system classpath and aren't loaded by the
thread context classloader.

Can you say more about why you are trying to load contribution classes
using the thread context classloader?

   Simon
>  
> 
> n  Sebastian
> 
> IDS Scheer Consulting GmbH
> Geschäftsführer/Managing Directors: Kamyar Niroumand, Ivo Totev
> Sitz/Registered office: Altenkesseler Straße 17, 66115 Saarbrücken, 
> Germany - Registergericht/Commercial register: Saarbrücken HRB 19681
> *http://www.softwareag.com*
>