java - Getting an object out of Equinox/Eclipse -


i facing problem combination of "plain" java, equinox, , communication between two. have read other related questions (here, here, , there other web sites, such this one , that one) not find satisfying (or working!) solution.

i have set of plug-ins: p1, p2, , p3. p1 export classes, used p2. p2 additionally exports other classes , interfaces, used p3. in particular, p2 defines , exports interface myinterface , implementation class myinterfaceimpl implements myinterface. p3 application and, thus, contains class launcher implements iapplication , defines public object start(iapplicationcontext) method. compiles fine. when run launcher eclipse application eclipse, runs fine. launcher uses myinterface , myinterfaceimpl fine.

now, programmatically run application using following (simple) code, seems "okay" way of running equinox/eclipse application, according various posts:

void callapplication() {     final string[] args =         new string[] {             "-application",             "launcher",             ... };     eclipsestarter.run(args, null); } 

again, piece of code works fine , can "see" application run , produce expected results.

now, here comes problem: obtain instance of myinterfaceimpl built application, running in equinox, inside "outer" java code. naïve solution return object in public object start(iapplicationcontext) method , modify calling code follows:

myinterface callapplication() {     final string[] args =         new string[] {             "-application",             "launcher",             ... };     return (myinterface) eclipsestarter.run(args, null); } 

but naïve solution not work. receive java.lang.classcastexception: myinterfaceimpl cannot cast myinterface. thinking of it, makes sense because, @ end of callapplication(), have 2 "versions" of pairs {myinterface, myinterfaceimpl}: 1 "outer" java code, loaded jvm class-loader, , equinox, loaded equinox class-loader. modified code print class-loaders of returned object , of myinterface:

final object o = eclipsestarter.run(args, null); system.out.println(o.getclass().getclassloader()); system.out.println(myinterface.class.getclassloader()); 

and, indeed, obtained:

org.eclipse.osgi.internal.baseadaptor.defaultclassloader@7e66458c[p2:1.5.0(id=413)] sun.misc.launcher$appclassloader@1efc3d2 

note class-loader of returned object said come p2, expected, because p2 plug-in defines , exports myinterface , myinterfaceimpl.

i tried different ways "compatible" pairs of {myinterface, myinterfaceimpl} no luck far (i same java.lang.classcastexception: myinterfaceimpl cannot cast myinterface):

  • i tried setting properties -dorg.osgi.framework.bootdelegation=* -dorg.osgi.framework.system.packages.extra=myinterface,myinterfaceimpl.

  • i tried intercepting defaultclassloader in start() method.

so, question is: is there way java program, uses classes defined in project, plug-in , export these classes, exchange instances of these classes instance of eclipse started programmatically? thanks!

ah, 1 tricky. suggest rearchitecting application , use plugins everything, not answer question.

now, want first, delete interface definition form p2 , add original (non-osgi) jar, preferably in package on own, let's com.example.api. then, add -dorg.osgi.framework.system.packages.extra=com.example.api; add imports in p2 , p3 package.

hope helps.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -