I'm having some problems following this tutorial (which was supposed to be quite easy):
http://www.javaworld.com/article/2077837/java-se/hello--osgi--part-1--bundles-for-beginners.html
At first the problem was the huge amount of errors whose source I couldn't find (but despite the errors, the output of the programme was correct). I read this about that problem:
This usually comes when someone tries to run a Java application against an OSGi bundle with java -classpath .... . It really means that the workbench plug-in hasn't started yet, and so calls to getWorkbench() fail. This is essentially a race condition, and can be solved by either expressing an explicit dependency on that bundle or bumping up that bundle to a higher start level than the workbench. Generally not seen, but if it is, that's what's happening.
I didn't understand the first solution the author presented, but I tried the second unsuccessfully. Then I reached the 5th (and last) page of the tutorial, and everything got worst. I tried to create the service factory as suggested by the author, and the outputs I was getting were not accurate. He states this:
Now try running this sample code. You should notice that it prints the service usage count as one (1) when HelloWorld bundle is started and zero (0) when the HelloWorld bundle is stopped.
But I was only getting the first output (usage counter printed as 1), and nothing else. While googling, I found this possible solution for the first problem, and I thought it might solve the second as well:
I struggled a lot for “Workbench has not been created yet” the complete day. But I got the solution by the following steps. Go to the Run configuration -> Remove all the target platform jars. Click on add required bundles. Check the org.apache.felix.gogo.runtime, org.apache.felix.gogo.shell, org.eclipse.eqinox.console, org.eclipse.osgi and your jar file. The last and important step. Go to Setting-> check the checkbox of "Clear the configuratation area before launching". Run the OSGi application now.
Enjoy if it works for you as it worked for me.
Does "removing all the target platform jars" mean that I should uncheck all the bundles in the Bundles tab in the Run Configurations? That's what I did, and it just got worse. By doing this, I was getting no output and some errors (not a bunch of them, like before), which I print below.
!ENTRY org.eclipse.osgi 4 0 2014-02-03 14:50:46.399 !MESSAGE Bundle reference:file:C:/Users/User/workspace/com.javaworld.sample.helloservice@5 not found.
!ENTRY org.eclipse.osgi 2 0 2014-02-03 14:50:46.473 !MESSAGE One or more bundles are not resolved because the following root constraints are not resolved: !SUBENTRY 1 org.eclipse.osgi 2 0 2014-02-03 14:50:46.474 !MESSAGE Bundle initial@reference:file:../../../workspace/com.javaworld.sample.helloworld/ was not resolved. !SUBENTRY 2 com.javaworld.sample.helloworld 2 0 2014-02-03 14:50:46.474 !MESSAGE Missing imported package com.javaworld.sample.service_0.0.0.
!ENTRY org.eclipse.osgi 2 0 2014-02-03 14:50:46.475 !MESSAGE The following is a complete list of bundles which are not resolved, see the prior log entry for the root cause if it exists: !SUBENTRY 1 org.eclipse.osgi 2 0 2014-02-03 14:50:46.475 !MESSAGE Bundle com.javaworld.sample.helloworld_1.0.0.qualifier [2] was not resolved. !SUBENTRY 2 com.javaworld.sample.helloworld 2 0 2014-02-03 14:50:46.475 !MESSAGE Missing imported package com.javaworld.sample.service_0.0.0.
Ok, I thought that just by selecting everything again (I think that it was the way it was before) I would be back on business, but now I'm getting no output at all. Any idea on what I'm doing wrong?