Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How do you load a JAR on your Plugin Classpath? (Snippet)
How do you load a JAR on your Plugin Classpath? (Snippet) [message #158480] Tue, 18 November 2003 16:31 Go to next message
Eclipse UserFriend
How do you load a JAR on your Plugin's classpath? Can someone post a code
snippet? I am unclear. I have reviewed the Ant stuff but I humbly require
just the classpath addition code.

Thanks,

David

--
David L. Whitehurst
aka. PiratePete
http://www.piratepetesoftware.com
dlwhitehurst@comcast.net
Re: How do you load a JAR on your Plugin Classpath? (Snippet) [message #158575 is a reply to message #158480] Tue, 18 November 2003 19:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pascal_rapicault.yahoo.fr

You can not add a jar onto your plugin classpath at runtime.
The only thing you can do is to create a classloader that will contain your
new jar and will then delegate to the eclipse classloaders.
Note that this is complicated and gives you an easy way to shoot yourself in
the foot.

Why do you need such a feature?

PaScaL

"David Whitehurst" <dlwhitehurst@comcast.net> a
Re: How do you load a JAR on your Plugin Classpath? (Snippet) [message #158601 is a reply to message #158575] Tue, 18 November 2003 20:15 Go to previous messageGo to next message
Eclipse UserFriend
Pascal:

I am creating a group of SQL related plugins to be a Database perspective.
I want to be able to add JDBC drivers (JARS) to a directory and be able to
check/uncheck those in the preferences so that logons (really JDBC
connections) will have access to the appropriate drivers.

Any ideas? I am up for most any at this point.

Thanks,

David

--
David L. Whitehurst
aka. PiratePete
http://www.piratepetesoftware.com
dlwhitehurst@comcast.net
"Pascal Rapicault" <pascal_rapicault@yahoo.fr> wrote in message
news:bpef2c$m27$1@eclipse.org...
> You can not add a jar onto your plugin classpath at runtime.
> The only thing you can do is to create a classloader that will contain
your
> new jar and will then delegate to the eclipse classloaders.
> Note that this is complicated and gives you an easy way to shoot yourself
in
> the foot.
>
> Why do you need such a feature?
>
> PaScaL
>
> "David Whitehurst" <dlwhitehurst@comcast.net> a
Re: How do you load a JAR on your Plugin Classpath? (Snippet) [message #158624 is a reply to message #158601] Tue, 18 November 2003 22:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pascal_rapicault.yahoo.fr

You should look at the AntClassLoader that is in the ant.core plugin.

PaScaL

"David Whitehurst" <dlwhitehurst@comcast.net> a
Re: How do you load a JAR on your Plugin Classpath? (Snippet) [message #158997 is a reply to message #158624] Wed, 19 November 2003 11:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: javibasi.yahoo.es

Hi

I didn't try, but as long as PluginClassLoader extends URLClassLoader, you
can use the addURL method to add a JAR file to the classpath at runtime.
This method is protected, so you will have to use reflection to invoke it.

Hope it helps

Dian Cecht


Pascal Rapicault wrote:

> You should look at the AntClassLoader that is in the ant.core plugin.

> PaScaL

> "David Whitehurst" <dlwhitehurst@comcast.net> a écrit dans le message de
> news: bpeg4o$n4u$1@eclipse.org...
> > Pascal:
> >
> > I am creating a group of SQL related plugins to be a Database perspective.
> > I want to be able to add JDBC drivers (JARS) to a directory and be able to
> > check/uncheck those in the preferences so that logons (really JDBC
> > connections) will have access to the appropriate drivers.
> >
> > Any ideas? I am up for most any at this point.
> >
> > Thanks,
> >
> > David
> >
> > --
> > David L. Whitehurst
> > aka. PiratePete
> > http://www.piratepetesoftware.com
> > dlwhitehurst@comcast.net
> > "Pascal Rapicault" <pascal_rapicault@yahoo.fr> wrote in message
> > news:bpef2c$m27$1@eclipse.org...
> > > You can not add a jar onto your plugin classpath at runtime.
> > > The only thing you can do is to create a classloader that will contain
> > your
> > > new jar and will then delegate to the eclipse classloaders.
> > > Note that this is complicated and gives you an easy way to shoot
> yourself
> > in
> > > the foot.
> > >
> > > Why do you need such a feature?
> > >
> > > PaScaL
> > >
> > > "David Whitehurst" <dlwhitehurst@comcast.net> a écrit dans le message de
> > > news: bpe2v3$9u2$1@eclipse.org...
> > > > How do you load a JAR on your Plugin's classpath? Can someone post a
> > code
> > > > snippet? I am unclear. I have reviewed the Ant stuff but I humbly
> > > require
> > > > just the classpath addition code.
> > > >
> > > > Thanks,
> > > >
> > > > David
> > > >
> > > > --
> > > > David L. Whitehurst
> > > > aka. PiratePete
> > > > http://www.piratepetesoftware.com
> > > > dlwhitehurst@comcast.net
> > > >
> > > >
> > >
> > >
> >
> >
Re: How do you load a JAR on your Plugin Classpath? (Snippet) [message #160405 is a reply to message #158480] Fri, 21 November 2003 19:34 Go to previous message
Eclipse UserFriend
A snippet.
I used it to load dynamically a jar and run it,
or more exactly invoke main(String[] ) on a class from the jar.

import java.io.File;
import java.lang.reflect.Method;
import java.net.*;
/**
* A class loader for loading jar files from a plugin
* Example use :
* String libName = "C:/java/javacc3.0/bin/lib/javacc.jar";
* String[] args = new String[1];
* args[0] = "C:/java/javacc3.0/examples/JavaCCGrammar/JavaCC.jj";
* ClassLoader cl = libName.getClass().getClassLoader();
* URL url = new URL("file", null, libName);
* JarLoader runtime = new JarLoader(url, cl);
* Class run = runtime.loadClass("org.netbeans.javacc.parser.Main");
* Method m = run.getMethod("mainProgram", new Class[] { args.getClass()});
* Object obj = c.newInstance();
* m.invoke(obj, new Object[] { args });
*
* Beware of working directory, which cannot be changed.
*/

class JarLoader extends URLClassLoader {
/**
* Creates a new JarClassLoader for the specified url.
* @param url the url of the jar file
*/
public JarLoader(URL url, ClassLoader parent) {
super(new URL[] { url }, parent);
}
}

HTH
Rémi Koutchérawy
Previous Topic:Eclipse for Linux - XmParseMappingCreate()
Next Topic:Programatically installing a plugin
Goto Forum:
  


Current Time: Thu May 08 10:38:01 EDT 2025

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

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

Back to the top