Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Loading jar at runtime
Loading jar at runtime [message #465817] Fri, 06 April 2007 10:18 Go to next message
Jochen Mader is currently offline Jochen MaderFriend
Messages: 24
Registered: July 2009
Junior Member
I know that this topic got several threads on the newsgroups but I don't
seem to be able to solve my problem.
We have several jar-files of which the path can only be determined at
runtime.
I need a way to load the jars and use the classes within inside my product.
I'm using the following codesnipplet:
ClassLoader classLoader = new URLClassLoader(new URL[] { (new File(PATH +
"alien.jar")).toURL() }, this.getClass().getClassLoader());
Thread.currentThread().setContextClassLoader(classLoader);

The jar gets found and loaded by the URLClassLoader, I can even use
loadClass to get the class I want to instantiate from the JarFile. But
here the problems begin.
All other classes in the jarfile on which the instantiated class depends
don't get loaded. What am I supposed to do?
Is there some way to load a jar file and make it's classes available to
the plugin classloader?
Do I have to replace the plugin classloader and if, hoe to do it?
I'm quite desperate, I couldn"t find anything on the net and if it's just
a RTFM then just paint the URL of the document to read on a baseballbat,
smash it over my head and I'll be a happy man.
Cheers
Jochen
Re: Loading jar at runtime [message #466285 is a reply to message #465817] Tue, 17 April 2007 13:32 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

jochen wrote:
> I know that this topic got several threads on the newsgroups but I don't
> seem to be able to solve my problem.
> We have several jar-files of which the path can only be determined at
> runtime.
> I need a way to load the jars and use the classes within inside my product.
> I'm using the following codesnipplet:
> ClassLoader classLoader = new URLClassLoader(new URL[] { (new File(PATH
> + "alien.jar")).toURL() }, this.getClass().getClassLoader());
> Thread.currentThread().setContextClassLoader(classLoader);
>
> The jar gets found and loaded by the URLClassLoader, I can even use
> loadClass to get the class I want to instantiate from the JarFile. But
> here the problems begin.
> All other classes in the jarfile on which the instantiated class depends
> don't get loaded. What am I supposed to do?
> Is there some way to load a jar file and make it's classes available to
> the plugin classloader?
> Do I have to replace the plugin classloader and if, hoe to do it?
> I'm quite desperate, I couldn"t find anything on the net and if it's
> just a RTFM then just paint the URL of the document to read on a
> baseballbat, smash it over my head and I'll be a happy man.
> Cheers
> Jochen
>
>

If you can work within the eclipse classloader's abilities, it'll work
much better for you.

For example, which kind of jar files are they ... real libraries that
you can't ship with your product for whatever reason? your libraries?
3rd party libraries? libraries like log4j or hibernate? "driver"
libraries (like JDBC)?


Eclipse deals in bundles (plugins) ...

Some "tricks" for being able to see "3rd party" libraries:

1) Create plugin-jars for them (basically just adding an OSGi MANIFEST)

2) Creating a core.lib plugin with the jars in them and then exporting them

3) creating a core.lib plugin that uses
external:${alien.lib.dir}/alien.jar and then setting your RCP to use
-Dalien.lib.dir on each install

4) dynamically building plugins out of the pre-installed jars when you
install

5) providing an OSGi level ClassLoaderHook of some kind, so that you can
provide OSGi compatible access to your libraries.

The folks over in eclipse.technology.equinox probably know more about
this kind of thing.

PW


Previous Topic:can I add plugins to a exsit RCP application?
Next Topic:Determine whether OS is XP or Vista
Goto Forum:
  


Current Time: Fri Apr 26 18:30:36 GMT 2024

Powered by FUDForum. Page generated in 0.03873 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top