Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Problems creating objects via reflection
Problems creating objects via reflection [message #1785870] Sat, 21 April 2018 09:54 Go to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 25
Registered: March 2016
Junior Member
Hi,

I'm writing an Eclipse plugin which relies on a library which creates objects based on reflection once initialized.

It uses org.reflections:reflections:0.9.11 if that matters.

When using that library in any other program which is not a Eclipse plugin (e.g. command line or web project) it works flawlessly, however Eclipse doesn't seem to allow the library to find anything via reflection.

Is this a problem with OSGi and is there a way to either allow it to do its thing or do I have to change something in the library itself? I would like to keep it working everyhwere.

Thanks in advance!
Re: Problems creating objects via reflection [message #1786120 is a reply to message #1785870] Wed, 25 April 2018 19:07 Go to previous messageGo to next message
Eclipse UserFriend
From the org.reflections doc, it scans and indexes the jars found on the classpath. That works fine in normal Java program as it has a flat classpath. OSGi on the other hand provides managed classpaths, such that each bundle has an independent classpath. You'll likely need to create a new Reflections instance for each bundle that you want to do lookups from, and somehow carry the appropriate reflections instance around.

Brian.
Re: Problems creating objects via reflection [message #1786735 is a reply to message #1786120] Thu, 10 May 2018 08:50 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 25
Registered: March 2016
Junior Member
Thank you for the hint Brian, I now see why it wouldn't work.

Is there a recommended way to accomplish it?

I have the following layout:


- eclipse-plugin -> all my UI stuff and where I need to instantitate objects from Library
- eclipse-plugin-library -> wrapper around Library to be able to use it as Eclipse plugin (just an exposed jar file)
- Library -> the actual library

So the dependencies (and maybe load order) is

eclipse-plugin
|
| depends on
|
\ /
eclipse-plugin-library
|
| depends on / provides
|
\ /
Library
Re: Problems creating objects via reflection [message #1786746 is a reply to message #1786735] Thu, 10 May 2018 14:32 Go to previous message
Eclipse UserFriend
It comes down to providing the classloader of the lookup location. It's best if you can pass the classloader, but sometimes setting the Thread's Context Class Loader can work too.
Previous Topic:How can I integrate papyrus plugin in my rcp application? I want to access papyrus editor in my rcp
Next Topic:Eclipse try to find an image that i don't use anymore!
Goto Forum:
  


Current Time: Sat Apr 20 01:41:25 GMT 2024

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

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

Back to the top