开发者

How to make project classes visible to the Eclipse plugin?

I'm new to eclipse plugin development, and I inherited some Eclipse plugin code and I'm trying to figure out how to do something relatively simple.

In a nutshell, you right-click on a Java class in your project, the wizard opens and the fully qualified classname of the selected Java class appears in a text field. When you click "next", the code attempts to do a CClass.forName(s) where s is th开发者_高级运维e class name.

The problem is, the Class.forName throws a class not found exception, I assume because the Java class in the eclipse project is not actually in the classpath of the wizard.

Can anyone point me in the right direction? How do I ensure the classes in the eclipse project are visible to the wizard, classpath-wise?


You cannot use Class.forName() for this. The java class in a Java project that your plugin operates on is not even in the same process as your plugin, let alone available for loading to any classloader.

You should be looking at JDT's Java Model or Java AST API to make a plugin that operates on Java files in a Java project.

http://www.vogella.de/articles/EclipseJDT/article.html


Each plug-in is loaded by a different class loader. However, there are ways you can load classes from other plug-ins. Reading these will help

http://www.eclipsezone.com/articles/eclipse-vms/

http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements


You must get the classloader in the selected java project first, then use the classloader to load class. Java project's classloader is different from the classloader in eclipse plugin. see the detail code in the following link: https://sdqweb.ipd.kit.edu/wiki/JDT_Tutorial:_Class_Loading_in_a_running_plugin

the code on the link will teach you how to get the classloader of the selected project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜