Search code examples
javaeclipseeclipse-pluginruntimeeclipse-classpath

Why i cant access the classes of my Eclipse plugin at Runtime?


I’m developing an Eclipse plugin, com.simple.plugin, with the following structure: Plugin Structure

The problem is that during runtime I cant access the classes of my own plugin. For example if I do the following code inside the SampleHandler.java:

Class cls = Class.forName("com.simple.handlers.SampleHandler");
Object obj = cls.newInstance();

I get the error:

java.lang.ClassNotFoundException: com.simple.handlers.SampleHandler cannot be found by com.simple.plugin_1.0.0.qualifier*

My manifest runtime option for classpath have the root of the plug-in, so I dont know what is wrong!


Solution

  • Your SampleHander class is in the com.simple.plugin.handlers package not the com.simple.handlers package. So the correct code is:

    Class<?> cls = Class.forName("com.simple.plugin.handlers.SampleHandler");
    

    You must always specify the full package name of the class you want.