Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How to get hold of a plugin's (or bundle's) classpath?
How to get hold of a plugin's (or bundle's) classpath? [message #209885] Fri, 15 July 2005 09:18 Go to next message
Eclipse UserFriend
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 #209971 is a reply to message #209885] Mon, 18 July 2005 08:34 Go to previous messageGo to next message
Eclipse UserFriend
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);

Later,
PW
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 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: How to get hold of a plugin's (or bundle's) classpath? [message #210152 is a reply to message #210078] Tue, 19 July 2005 09:48 Go to previous messageGo to next message
Eclipse UserFriend
Michael Moser wrote:
>
> [... snip ...]
> 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
>

You can use Bundle.getEntry() and Platform.asLocalURL()

http://dev.eclipse.org/newslists/news.eclipse.platform/msg42 343.html

Later,
PW
Re: How to get hold of a plugin's (or bundle's) classpath? [message #211981 is a reply to message #210152] Wed, 10 August 2005 08:24 Go to previous message
Eclipse UserFriend
Hi Paul,
sorry for the late reply - I was on vacation.

"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:dbj0cg$m1u$1@news.eclipse.org...
> Michael Moser wrote:
>>
>> [... snip ...]
>
> You can use Bundle.getEntry() and Platform.asLocalURL()
>
> http://dev.eclipse.org/newslists/news.eclipse.platform/msg42 343.html
>
> Later,
> PW

Thanks - that indeed did the trick!

Regards,
Michael
Previous Topic:Add source files to jarpackagedata
Next Topic:Howto change the higlight color of the actual row while debugging?
Goto Forum:
  


Current Time: Mon Jun 09 15:06:03 EDT 2025

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

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

Back to the top