Why can't I access the classes of my Eclipse plugin in Runtime?

Im developing an Eclipse plugin,, com.simple.pluginwith the following structure: Plugin structure

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

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

I get an error message:

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

My runtime parameter for classpath has a plugin root, so I don’t know what is wrong!

+4
source share
2 answers

Your class SampleHanderis in a com.simple.plugin.handlers non- package package com.simple.handlers. Therefore, the correct code is:

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

, .

+2

Eclipse . , - .

Buddy Eclipse osgi. manifest.mf:

Eclipse-BuddyPolicy: Registered

, manifest.mf.

Eclipse-RegisterBuddy: {NAME OF THE PARENT PLUGIN}

:

Eclipse-RegisterBuddy: de.myname.myplugin

.

. :

https://wiki.eclipse.org/Context_Class_Loader_Enhancements

+1

Source: https://habr.com/ru/post/1626238/


All Articles