I am learning OSGi follow this Apache Felix Tutorial, everything went on wheels until this example 5, I've been told that felix couldn't find the class org.osgi.util.tracker.ServiceTracker
. I copied all the exact code and the manifest meta data on the page, I'm totally confused, can someone help me with this?
Asked
Active
Viewed 1,075 times
0

Gale Yao
- 133
- 1
- 10
-
What is the *actual error message*? – Neil Bartlett Sep 09 '16 at 22:07
1 Answers
1
ServiceTracker is part of OSGi core since version 5.0. That means that if you use an Apache Felix that already supports OSGi 5, the JAR will contain the class you are looking for.
If you want to have the class for compilation, you add the osgi-core 5 jar file the classpath of the compiler.

Balazs Zsoldos
- 6,036
- 2
- 23
- 31
-
Yes, I know that, I have OSGi core 5 and I can compile the class, but when I start the bundle after generate the bundle jar, it tells me couldn't find the class org/osgi/util/tracker/ServiceTracker, I can see this class is located in osgi-core.jar at org.osgi.util.tracker, so why this error, it seems strange and impossible somehow. – Gale Yao Sep 09 '16 at 14:32
-
The OSGi jar should not be in the runtime because the OSGi classes are supposed to be provided by the Framework. Remove the OSGi jar from your bundles directory. – Renato Sep 09 '16 at 19:06
-
If you look at the Felix jar (system bundle), you'll see it does export `org.osgi.util.tracker`, so as long as you have the correct version of Felix it should work. This is the bundle I am using and it works: org.apache.felix.framework-5.4.0.jar – Renato Sep 09 '16 at 19:14
-
@Renato I used version 6.0.0, the class ServiceTracker dose exist in package `org.osgi.util.tracker`, and the OSGi does export it, the IDEA compiled my bundle successfully and I got my bundle jar named **example5.jar**, but I still cant start it, it's so weird. Oh, the error message is said _java.lang.NoClassDefFoundError: org/osgi/util/tracker/ServiceTracker_ – Gale Yao Sep 10 '16 at 09:17
-
What do you mean by "start the bundle". Is org.osgi.util.tracker listed in the Import-Package MANIFEST header of your bundle? – Balazs Zsoldos Sep 10 '16 at 17:31
-
1@GaleYao Have you checked that your bundle imports the package `org.osgi.util.tracker`? – Neil Bartlett Sep 11 '16 at 09:44
-
Thank you all very much, I've fixed the problem, it was something stupid, sry. – Gale Yao Sep 14 '16 at 03:15