Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Access a Java Project's class files through a plugin
Access a Java Project's class files through a plugin [message #1067595] Tue, 09 July 2013 13:57 Go to next message
Tobias Freudenreich is currently offline Tobias FreudenreichFriend
Messages: 19
Registered: July 2013
Junior Member
Hi,

I am trying to get access to the class files of a Java Project from a plugin. The idea is that the user writes some Java classes and eventually invokes a handler of my plugin (e.g., through a menu). Furthermore, the user created a config-file in the same project which contains the fully qualified names of some Java classes.

I can read the fully qualified names without any problem in my plugin, now what I would like to do is instantiate the given classes (present in the project) from within my plugin.

I tried using Class.forName() which happens (not much to my surprise). However, I can't seem to come up with working way.

Does anyone know if/how this is possible?
Re: Access a Java Project's class files through a plugin [message #1067639 is a reply to message #1067595] Tue, 09 July 2013 18:18 Go to previous messageGo to next message
Mark Leone is currently offline Mark LeoneFriend
Messages: 67
Registered: April 2012
Member
What's the problem with using Class.forName()? It's not clear to me from your message.
Re: Access a Java Project's class files through a plugin [message #1067660 is a reply to message #1067595] Tue, 09 July 2013 20:31 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
You need to create a custom classloader which includes your projects
classpath.

You can take a look at e(fx)clipse which constructs such a classpath
from the JavaProject definition [1,2].

Tom

[1]http://git.eclipse.org/c/efxclipse/org.eclipse.efxclipse.git/tree/bundles/tooling/org.eclipse.fx.ide.ui.preview/src/org/eclipse/fx/ide/ui/preview/LivePreviewSynchronizer.java#n157
[2]http://git.eclipse.org/c/efxclipse/org.eclipse.efxclipse.git/tree/bundles/tooling/org.eclipse.fx.ide.ui.preview/src/org/eclipse/fx/ide/ui/preview/LivePreviewPart.java#n399

On 09.07.13 15:57, Tobias Freudenreich wrote:
> Hi,
>
> I am trying to get access to the class files of a Java Project from a
> plugin. The idea is that the user writes some Java classes and
> eventually invokes a handler of my plugin (e.g., through a menu).
> Furthermore, the user created a config-file in the same project which
> contains the fully qualified names of some Java classes.
>
> I can read the fully qualified names without any problem in my plugin,
> now what I would like to do is instantiate the given classes (present in
> the project) from within my plugin.
> I tried using Class.forName() which happens (not much to my surprise).
> However, I can't seem to come up with working way.
>
> Does anyone know if/how this is possible?
Re: Access a Java Project's class files through a plugin [message #1067702 is a reply to message #1067660] Wed, 10 July 2013 08:10 Go to previous messageGo to next message
Tobias Freudenreich is currently offline Tobias FreudenreichFriend
Messages: 19
Registered: July 2013
Junior Member
Mark, the problem with Class.forName is that the project's class file is not accessible for the plugin.

Thomas, thanks for the reply. I'll look into this, even though I was hoping to avoid the issue of creating my own classloader.
Re: Access a Java Project's class files through a plugin [message #1067710 is a reply to message #1067702] Wed, 10 July 2013 08:55 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
You have to where from should the running eclipse know about classes you
are just developing in your workspace?

Tom

On 10.07.13 10:10, Tobias Freudenreich wrote:
> Mark, the problem with Class.forName is that the project's class file is
> not accessible for the plugin.
>
> Thomas, thanks for the reply. I'll look into this, even though I was
> hoping to avoid the issue of creating my own classloader.
Re: Access a Java Project's class files through a plugin [message #1069725 is a reply to message #1067710] Tue, 16 July 2013 13:02 Go to previous messageGo to next message
Tobias Freudenreich is currently offline Tobias FreudenreichFriend
Messages: 19
Registered: July 2013
Junior Member
Tom,
conceptually, I totally know that the running eclipse doesn't have easy access to the classes. However, with all the functionality eclipse provides (content assist, etc.) I was hoping that the infrastructure might provide some kind of API to do exactly that: load classes from a project.
I guess I'll have to walk this on my own.
Re: Access a Java Project's class files through a plugin [message #1069825 is a reply to message #1069725] Tue, 16 July 2013 16:38 Go to previous message
David Wegener is currently offline David WegenerFriend
Messages: 1352
Registered: July 2009
Senior Member
You should consider the implications of loading an unknown class file into a running Eclipse instance. The class can do things that will make Eclipse unstable or even crash. Any static initializers in the class will be run when it is loaded. Dependent classes will attempt to be loaded, bugs in the users code will be executed, etc. If the class can be edited in the running Eclipse instance, you also have the problem of unloading and reloading the class when it is changed. If you really need to deal with user created classes, you should think about launching a separate application instance to test them out.
Previous Topic:Meaning of colon (:) in a handler's class= statement (plugin.xml)
Next Topic:Remove old JARs from Update Site
Goto Forum:
  


Current Time: Sun Dec 21 22:25:13 GMT 2014

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

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