OSGI - calling static methods through packages

I have a third party JAR that I converted to an OSGI package using bnd. The code I need to call in order to use it from my own package looks something like this:

ThirdParty.setRegKey(myRegKey);
ThirdParty thirdParty = new ThirdParty();
thirdParty.callMethod();

      

What seems to be causing me problems is the first line - the call to the static method. Outside of an OSGI container, using a standard JAR, this works great. However, on OSGI, I get an error on line 3 which states that the registration key is not installed.

Are there any problems with static method calls in such bundles? It is almost as if the static context was not shared between bundles.

+2


source to share


2 answers


Have you debugged the code? Since you will not tell us which third party library you are working with and we do not know your complete environment, it is possible that setRegKey()

or callMethod()

are trying to do something "smart" that does not work inside OSGi.



The JDBC Driver Manager has this issue where your package imports the JDBC driver class, but the driver manager decides that the calling thread from your package should not "see" the JDBC driver class, so it doesn't work when run inside OSGi.

+2


source


You may need to export / import the package containing the ThirdParty class. Otherwise, it ends up in different classloaders for different packages, so it really isn't used.



The true OSGi way would be to do it with some service.

+2


source







All Articles