Skip to main content



      Home
Home » Eclipse Projects » Equinox » LinkageError when calling a method
LinkageError when calling a method [message #95367] Mon, 20 August 2007 14:28 Go to next message
Eclipse UserFriend
Originally posted by: fergonco.gmail.com

Hi,

I have two Equinox bundles. In one of them I have defined a public static attribute. I want to access that attribute from the other bundle. The attribute is from a third party library that is included in the Bundle-ClassPath of the manifest of both bundles.

The following code in the accessing plug-in fails with LinkageError:
IntValue i = dep1.Activator.dsf;
System.out.println(i.getValue());

If I remove the method invocation and I just print the instance it works:
System.out.println(i);

Does anyone know why it is happening? is this the right way to share some instance between two bundles? Can this be done or should I use some communication using services?

Thanks in advance,
Fernando

the exception I get is the following



org.osgi.framework.BundleException: Exception in org.orbisgis.geocatalog.folder.Activator.start() of bundle org.orbisgis.geocatalog.folder.
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.s tartActivator(BundleContextImpl.java:1018)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.s tart(BundleContextImpl.java:974)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWor ker(BundleHost.java:346)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.star t(AbstractBundle.java:260)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.star t(AbstractBundle.java:252)
at org.eclipse.osgi.framework.internal.core.FrameworkCommandPro vider._start(FrameworkCommandProvider.java:260)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.osgi.framework.internal.core.FrameworkCommandInt erpreter.execute(FrameworkCommandInterpreter.java:145)
at org.eclipse.osgi.framework.internal.core.FrameworkConsole.do command(FrameworkConsole.java:291)
at org.eclipse.osgi.framework.internal.core.FrameworkConsole.co nsole(FrameworkConsole.java:276)
at org.eclipse.osgi.framework.internal.core.FrameworkConsole.ru n(FrameworkConsole.java:218)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.LinkageError: org/gdms/data/values/IntValue
at org.orbisgis.geocatalog.folder.Activator.start(Activator.jav a:12)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2 .run(BundleContextImpl.java:999)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.s tartActivator(BundleContextImpl.java:993)
... 14 more
Re: LinkageError when calling a method [message #95397 is a reply to message #95367] Mon, 20 August 2007 15:07 Go to previous messageGo to next message
Eclipse UserFriend
Fernando,

Does the accessing bundle import the package org.gdms.data.values or
require another bundle which exports that package?

From your description I'm not sure why you are getting a LinkageError.
How tightly coupled do you want your bundles? Right now I would say
your bundles are very tightly coupled because you are accessing a static
field from one bundle's Activator class in another. As a best practice
I would not make a bundle's activator class API which can be used from
another bundle. Instead you should create real API in a separate
package which can be shared among multiple bundles.

There are many options to share data across bundles. Here are just a few:

1) Use the OSGi registry. I know nothing about the IntValue class, but
I can imagine that object can be registered as a service with specific
properties describing what the IntValue is for. Or you can develop a
separate interface API which has getters to get IntValues and other data
and then register an instance of that interface as an OSGi service.

2) Use the Eclipse extension registry to contribute to an extension point.

3) Although not recommended by OSGi purests ... many APIs in Eclipse
have static getter methods on API classes which get object instances.
Pretty similar to what you describe but is more formalized as API
instead of some internal static field.

HTH.

Tom.


Tom
Re: LinkageError when calling a method [message #95411 is a reply to message #95397] Mon, 20 August 2007 16:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: fergonco.gmail.com

Thanks for your help Tom.

The code is in an Activator just for testing purposes but I have moved it to a event handler in a swing component and the behavior is the same. I think it should work in the same way since everything is resolved when I try to start that plugin, shouldn't it?

In this case we need an instance to be accessible by a lot of bundles. The type of the instance is provided by another project independent of the bundles and is provided in a separated jar file. So I think it makes no sense to export the package in one of them and import it in the other, doesn't it?

I think the first approach you mention fits my needs but I have developed some eclipse plug-ins and I'm used to the third one. I think I didn't describe well my problem because I think it's EXACTLY what I want.

Best regards,
Fernando
Re: LinkageError when calling a method [message #95426 is a reply to message #95397] Mon, 20 August 2007 17:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: fergonco.gmail.com

Sorry Tom, it works. I think I misunderstood you in my previous message.

I have added the third party jar in the "Bundle-ClassPath" header of one of the bundles. In that bundle I have exported the package in the jar that contains the type of the public static instance. In the rest of the bundles I just have to import that package or require the plugin but NOT add the jar to the "Bundle-ClassPath"

Thanks again for your help.

Best regards,
Fernando
Re: LinkageError when calling a method [message #95550 is a reply to message #95426] Tue, 21 August 2007 10:33 Go to previous message
Eclipse UserFriend
Great, glad you are working now. If you place the same jar in the
Bundle-ClassPath of multiple bundles then each bundle will have a
private copy of the code and will load the code from their own private
copy. This will cause ClassCastExceptions in most cases. It seems in
your particular case you are getting a LinkageError which is kinda strange.

I sounds like you are on the right track now by having only one bundle
with the code which exports the packages and have the rest of the
bundles import the packages or require the bundle which exports the packages

Tom.
Previous Topic:Using xpath in an osgi bundle
Next Topic:IncompatibleClassChangeError accessing EJBs resided in different EAR through local interface from HT
Goto Forum:
  


Current Time: Tue Jul 08 17:28:48 EDT 2025

Powered by FUDForum. Page generated in 0.05085 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top