How to get hold of a plugin's (or bundle's) classpath? [message #209885] |
Fri, 15 July 2005 09:18  |
Eclipse User |
|
|
|
My plugin calls the java compiler to dynamically compile classes, i.e.
my plugin has, so-to-speak, the ability to extend itself during runtime.
To be able to properly compile the classes, the compiler needs of course
get passed a proper classpath, which in my case would need to be the
bundle's own classpath.
Ho do I get hold of this classpath? I first naively tried using
System.getProperty("java.class.path") but that didn't return anything
and meanwhile I found out, that for plugins the System-properties are in
fact completely empty.
I then tried via the BundleContext which has a method with the very
promising signature "String getProperty(String key)" and which is passed
in at startup via the "void start(BundleContext ctxt)" - method), but
again, apparently no classpath (I tried with the keys "java.class.path"
and "Bundle-ClassPath" as specified in the bundle's manifest.mf file).
So, how can a plugin get hold of its own classpath???
Michael
|
|
|
|
Re: How to get hold of a plugin's (or bundle's) classpath? [message #210078 is a reply to message #209971] |
Mon, 18 July 2005 18:07   |
Eclipse User |
|
|
|
Hi Paul,
thanks for the response!
"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:dbg7lk$dj5$1@news.eclipse.org...
> Hey-o Michael,
>
> I haven't seen getProperty() used, but I have seen getHeaders():
>
> String mypath = (String)
> MyPlugin.getDefault.getBundle().getHeaders().get(org.osgi.fr amework.Constants.BUNDLE_CLASSPATH);
That far I actually already came (though your solution is definitely
more elegant - mine first got hold of the manifest file resource and
than did a Property.load and then extracted the class-path as one of the
keys from these properties).
However, that only gives me the *relative* classpath, i.e. the class
path relative to the base directory where the plugin is installed. What
I need is the "absolute" classpath of the bundle's installation
directory (i.e. the directory where the plugin's plugin.xml file sits).
That, path-fragment by path-fragment, combined with the above bundle
classpath would then yield the complete classpath which I need to pass
to the java compiler.
To make things clearer:
If the bundle is, say, installed in "C:\eclipse\plugins\foo_1.0.0" and
the BUNDLE_CLASSPATH is, say, "bar, lib\somelibrary.jar", then I need to
pass
the classpath
" C:\eclipse\plugins\foo_1.0.0\bar;C:\eclipse\plugins\foo_1.0. 0\lib\somelibrary.jar "
to the java compiler to get my stuff properly compiled.
What I am lacking is the first part, i.e. the
"C:\eclipse\plugins\foo_1.0.0"-part. That's what I meant with: how can a
bundle figure out the absolute path of the directory from where it was
loaded.
Hope I could make myself clear...
Michael
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.27147 seconds