Re: Loading jar at runtime [message #86866] |
Tue, 17 April 2007 13:32 |
|
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
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Powered by
FUDForum. Page generated in 0.03127 seconds