cancel
Showing results for 
Search instead for 
Did you mean: 

Loading classes from different components?

Former Member
0 Kudos

Hi,

I understand that my portal component can instantiate (API)-classes of all components referenced in the (Private)SharingReference of portalapp.xml. But my problem is I don't know in advance what classes from which .pars my component is going to instantiate via reflection, so I can't put them into the SharingReference.

My question: how can I tell the classloader during runtime, not deploy time, to dynamically load a different portal component?

Any hints are very welcome.

Regards

John

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

it's for sure a hack, but you may try this one:

<code>

AutoClassLoader cl = (AutoClassLoader) this.getClass().getClassLoader();

ClassLoader componentClassLoader = iwizardcontext.getRequest().getComponentContext().getComponent().getClass().getClassLoader();

cl.registerDelegationLoader("somestring",componentClassLoader);

// do your dirty doings here

cl.unregisterDelegationLoader("somestring");

</code>

Former Member
0 Kudos

I wouldn't recommend this in a million years,

but a nice hack is to instansiate a new URLClassloader and initialize it with a set of jar files from the components you wish to use.

A security manager might prevent this though.

Also have a look at the classes

com.sapportals.portal.prt.util.AutoClassLoader and com.sapportals.portal.prt.util.ApplicationClassLoader

I believe these are the classes which do the job for the portal runtime

Let me know how this goes