Hi,
is there a way to exchange data between a v1 and a v2 plugin? Any clue how to do this?
Thanks!
Community moderators have prevented the ability to post new answers.
Yes, of course.
1) Setting the correct class loader (usually belonging to a class in the WEB-INF/lib helps)
2) If you cannot go past beyond the class loader issues (may happen in some special cases) just remember: reflection is always good ;)
#ifdef _UNSAFE_
clz = Class.forName("my.innaccessible.clazz", true, com.atlassian.jira.ComponentManager.class.getClassLoader());
Method m = clz.getMethod("executeTheDamnMethod", String.class, Integer.class);
m.invoke(null, "string here", -1); //this is a static one
.....................
#endif
thx
how about the other way: Access a component of a v2- from a v1-plugin?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
so evil yet so easy ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Michael Stelzner.
It's a bit harder because you have to determine in which class loader the class was loaded (go up in the hierarchy of the OSGI bundles). Once you figure it out, same stuff.
BUT: You can always do a callback: Like for instance, the V2 plugin "registers" itself (calls back with 'this' ) a method on the V1 :)) hehe
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Radu,
thanks for the classloader hint. I was able to connect my v2 to the v1 and execute some methods.
Haven't tried the other way yet.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Radu,
thanks so much ... this saved me a lot of time today :-)
Regards,
Dieter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey
I exported my component in a V1 plugin using the <component> declaration in atlassian-plugin.xml. After that, I tried the following from a V2 plugin:
Class<?> clz = Class.forName("com.myplugin.MyComponentInterface.class", true,com.atlassian.jira.ComponentManager.class.getClassLoader()); Method m = clz.getMethod("sayHello", String.class); m.invoke("John");
and it gives me a java.lang.ClassNotFoundException.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What if I export a component from a V1 plugin, and it doesn't have a static method?
The m.invoke(...) method takes an object as the first parameter (null if it is static). How do I get that object?
I tried doing the following:
Class<?> clz = Class.forName("com.myplugin.MyComponentInterface", true, com.atlassian.jira.ComponentManager.class.getClassLoader()); Method m = clz.getMethod("sayHello", String.class); m.invoke(ComponentManager.getComponent(MyComponentInterface.class), "John");
I tried using ComponentManager.getComponent(...) to get my object, but it gives me a NullPointerException.
Any idea how to access V1 components from V2, without using static methods?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.