views:

251

answers:

1

Hi All,

I have developed an eclipse plugin which references an external jar present in a external installation directory. So I have added an entry to my bundle classpath as below:

Bundle-ClassPath: external:C:\mylib.jar

My class loads properly - and the plugin is able to detect a class MyClass present in this external lib.
However, the method a() - I am calling in the class MyClass is failing.

Method a() is as follows :

public void a()
{
  URL url = this.class.getClassLoader().getResource("META-INF/startup-jar ");
  ...
}

so the URL which is returned is that of the eclipse plugin directory C:\eclipse3.4\test and not of the physical location of the external jar which is C:\mylib.jar

This is causing method a() to fail. Now, my question is -
As I don't have the external jar copied to my plugin directory (it is only present on the plugin classpath)

how can I ensure the classloader gets the URL path of my external jar and not of my plugin directory?

Note : I cannot change the classloading mechanism in the external jar as it is a third party dependency and I have no control over the code. So please suggest a solution which would help me to load the external jar class correctly so I can get the correct URL.

Thanks a lot for your help - in advance

To explain a bit more on the problem I am facing :: My external jar is present inside the installation directory of my server installation.

When the class in my external jar calls the URL url = this.class.getClassLoader().getResource("startup-jar")

it returns the URL relative to the eclipse bundle path - Something like C:\eclipse3.4...

and this URL is used for getting the boot directory (installation directory of the server) .

So it should have returned a path which is relative to the server installation directory, but instead returns a path relative to the eclipse installation directory.

Because of this, I am not able to call any APIs on the server as the server installation directory which it tries to use is incorrect.

So I wanted to know what is the best way I can handle this, so that this method call returns the server installation dir and not eclipse bundle path.

A: 

Can't you wrap this 3rd party dependency with the correct OSGI metadata and install it as a plug-in/bundle? We did this for all 3rd-party dependencies, including problematic ones such as Hibernate and made them work.

If it's a popular open source library, you can probably find it with the OSGi metadata added at Spring's repository: www.springsource.com/repository/app

In general, I wouldn't recommend the pattern of referencing external JARs as you describe in your question.

hbunny
By 'wrap this third-party dependency' do you mean- I copy all these jars under libs of another plugin and then add them to the bundle classpath of this new plugin?And then add this new plugin to the bundle classpath of the first plugin?Will this approach make any difference to the value returned by the getResource method?
deepthinker121
If method a() is in the 3rd-party library, then yes it should work because the 3rd party library will have its own class loader. I wasn't sure if you had a specific reason for NOT having the library available as a bundle/plug-in.
hbunny