Make system classloader aware of a class in jboss

A

Adam

I need to make the system class loader know about a class which isn't on the
classpath, but is loaded at run time.
Other classes on the classpath (and hence are loaded by system class loader)
need to be able to use this runtime loaded class. How can I do this?

A bit of background might help: I'm using JBoss with JFreeReport (the latter
library isn't important). The JFreereport classes are on the classpath when
JBoss is started, so everything can see them.
However, JFreeReport cannot see classes which are deployed in jboss as
(presumably) they will have to be loaded using a different class loader.
JFreereport is trying to load a couple of the deployed classes at runtime
using Class.forName(), but cannot find the class, as it is trying to use the
default class loader.
I'm hoping that perhaps there is someway of 'adding' these classes to system
class loader at run time so it will find them, tho I've had no luck so far.

Any ideas?

adam
 
O

Oscar kind

Adam said:
I need to make the system class loader know about a class which isn't on the
classpath, but is loaded at run time.
Other classes on the classpath (and hence are loaded by system class loader)
need to be able to use this runtime loaded class. How can I do this?

You can't. Every classloader has a place it gets its classes from. In
case of the system classloader and similar classloaders, this is a
classpath.

This is also the reason that if you define a data source for an
application, the application server must have the database driver in it's
classpath; not merely the application.

A bit of background might help: I'm using JBoss with JFreeReport (the latter
library isn't important). The JFreereport classes are on the classpath when
JBoss is started, so everything can see them.

Which classloader has JFreeReport? Most application servers have a
classloader for itself (the system classloader), a classloader for all
applications, a classloader for each application and a classloader for
each component of an application (so a web application cannot access the
classes of the EJB component).

However, JFreeReport cannot see classes which are deployed in jboss as
(presumably) they will have to be loaded using a different class loader.
Correct.


JFreereport is trying to load a couple of the deployed classes at runtime
using Class.forName(), but cannot find the class, as it is trying to use the
default class loader.

Not entirely. It asks it's own classloader. That classloader searches
its own classpath (or wherever it gets its classes from), and/or asks its
parent classloader (it can also ask its parent first, but I digress).

I'm hoping that perhaps there is someway of 'adding' these classes to system
class loader at run time so it will find them, tho I've had no luck so far.

There might be, but I don't know of any classloader inplementations that
allow this. First, you'll have to find out which classloader is being used
by JFreeReport (add your own class to that classpath, and ask that class).
Then, you'll have to find documentation for it, or decompile, and hope
there is a solution. It's a lot of work with little chance of success.

Check out my second paragraph (about data sources and database drivers).
It might give you a more feasible idea.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top