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:
A couple of circumstances need to exist to trigger this error:
- JDK7 is used
- Apache Felix 4.0.2 or 4.0.3 is used
- javac is used to compile the project
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.
Official OSGi Site:
OSGi R4: http://www.osgi.org/Release4/Download
(OSGi R5: http://www.osgi.org/Release5/Download)
Discussions regarding this issue:
- Apache Felix: http://felix.apache.org/
Source code of OSGi snippets is at the project site: