java - Class defined in another plugin cannot be found by the main plugin - Eclipse Product -


i exported plugin project product , when run product (eclipse application), main plugin (org.example.framework.core) cannot find class defined in plugin (org.example.abc) implements extension extension point provided main plugin. class 1 of elements defined in extension. however, when run project in eclipse, runs fine!

here log (atvste.ppt.ptfwdescription.abc.decoderinfo package in org.example.abc plugin):

0 [worker-2] error org.example.framework.core.ptfw.codec.decode.msgdecoderinfo org.example.framework.core.ptfw.codec.decode.msgdecoderinfo.createinstance(msgdecoderinfo.java:114) : can not create class :atvste.ppt.ptfwdescription.abc.decoderinfo.msgdecoderinfoabc atvste.ppt.ptfwdescription.abc.decoderinfo.msgdecoderinfoabc cannot found org.example.framework.core_1.0.0.201404111439 java.lang.classnotfoundexception: atvste.ppt.ptfwdescription.abc.decoderinfo.msgdecoderinfoabc cannot found org.example.framework.core_1.0.0.201404111439 @ org.eclipse.osgi.internal.loader.bundleloader.findclassinternal(bundleloader.java:501) @ org.eclipse.osgi.internal.loader.bundleloader.findclass(bundleloader.java:421) @ org.eclipse.osgi.internal.loader.bundleloader.findclass(bundleloader.java:412) @ org.eclipse.osgi.internal.baseadaptor.defaultclassloader.loadclass(defaultclassloader.java:107) @ java.lang.classloader.loadclass(unknown source) @ java.lang.class.forname0(native method) @ java.lang.class.forname(unknown source) @ org.example.framework.core.ptfw.codec.decode.msgdecoderinfo.createinstance(msgdecoderinfo.java:104) @ org.example.framework.core.ptfw.codec.decode.decoderinfo.<init>(decoderinfo.java:56) @ org.example.framework.core.ptfw.codec.decode.decoderinfo.createinstance(decoderinfo.java:125) @ org.example.framework.core.ptfw.codec.ptfwobjectsfactory.decoderinfoitf_createinstance(ptfwobjectsfactory.java:200) @ org.example.framework.persistence.jaxb.ptfwdescriptionpersistencejaxb.createptfwdescription(ptfwdescriptionpersistencejaxb.java:326) @ org.example.framework.persistence.jaxb.ptfwdescriptionpersistencejaxb.fillptfwdescription(ptfwdescriptionpersistencejaxb.java:247) @ org.example.framework.persistence.jaxb.ptfwdescriptionpersistencejaxb.createinstance(ptfwdescriptionpersistencejaxb.java:232) @ org.example.framework.persistence.jaxb.ptfwdescriptionpersistencejaxb.open(ptfwdescriptionpersistencejaxb.java:146) @ org.example.framework.core.ptfw.codec.ptfwdescription.createinstance(ptfwdescription.java:152) @ org.example.framework.core.ptfw.codec.command.cmdloadptfwdescription.loadptfwdescription(cmdloadptfwdescription.java:50) @ org.example.framework.core.ptfw.codec.command.cmdloadptfwdescription.execute(cmdloadptfwdescription.java:40) @ org.example.framework.core.runtime.jobservice$2.run(jobservice.java:93) @ org.eclipse.core.internal.jobs.worker.run(worker.java:53)

edit: function creating instance of class not found

 public static imessagedecoderinfo createinstance(xmlgmsgdecoderinfo pmsgdecoderinfotype,         imessagedecoderinfo msgdecoder) {      string classname = pmsgdecoderinfotype.getclassname();     if(classname!=null)     {         try         {             class<?> formalargs[] = new class[1];             formalargs[0] = xmlgmsgdecoderinfo.class;             class<?> clazz;             if (msgdecoder != null)             {                 clazz = msgdecoder.getclass();             }             else             {                 clazz = class.forname( classname );             }             constructor<?> constructor = clazz.getconstructor(formalargs);             java.lang.object  actualargs[] =             { pmsgdecoderinfotype };              return (imessagedecoderinfo)constructor.newinstance(actualargs);         }catch(exception e) {             string error = "can not create class :" +classname+ " " + e.getmessage();             if (logger.isenabledfor(level.error)) {                 logger.error(error, e);             }             throw new createptfwelementruntimeexception(error, e);         }     }     return new msgdecoderinfo(pmsgdecoderinfotype); }` 

because of complex class loader system used eclipse cannot use class.forname load class in plugin.

if code processing extension point definition have iconfigurationelement configuration element specifies class name. can use

iconfigurationelement configelement = ....;  object classinstance = configelement.createexecutableextension("class attribute name"); 

where 'class attribute name' name of attribute in extension point element specifies class load. class being created must have no argument constructor.

alternatively can load class using:

bundle bundle = platform.getbundle("plugin id");  class<?> theclass = bundle.loadclass("class name");  ... construct usual ... 

if have iconfigurationelement can plugin id using

string pluginid = configelement.getcontributor().getname(); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -