Donnerstag, 28. Februar 2013

Error: type ServiceReference does not take parameters

When developing for an OSGi environment and especially when using
Apache Felix derived projects, one may run into a strange error. It is strange,
because inside Eclipse no errors are shown, but when using the Java compiler
(javac), it complains like so:

OSGi code is compiled with the -jsr14 option and that leads to problems
with the JDK7 compiler. The Eclipse JDT compiler compiles it well, and therefore there
is no error when building only in Eclipse.

There are updated OSGi jars available now which fix this problem (and
one doesn't need to recompile). These are org.osgi.core-4.3.1.jar
and org.osgi.compendium-4.3.1.jar. They are on OSGi's site or on the
maven sites. (See below)

My fix for an earlier project was to build the OSGi sources
(org.osgi.* packages) with JDK7 and put them before the Felix jars in the
classpath. This makes the new OSGi class files being used instead of
the ones which are packaged with the Felix jars.