Sometimes on a project you know that you just have to write a blogpost, because you struggled too long with an issue to get it resolved.
The goal :
We wanted to use the twitter4j api inside on our Java-classes in the CQ5.4 installation.
The development was ok, and via maven we used the following dependency to make the code work :
So far so good, deployment is then the next step. We use the “maven-bundle-plugin” to generate the manifest file for the OSGi-bundle.
After the deployment, the following errors showed up in the system-console (http://localhost:4502/system/console/bundles/)
twitter4j — Cannot be resolved
twitter4j.conf — Cannot be resolved
And the status of the bundle was set to “Installed” and not “Resolved”
These errors were caused because I didn’t put the twitter4j packages in the <Export-Package> element of the “maven-bundle-plugin”.
Here an example how I added the twitter4j in the <Export-Package> element.
Next round, Next deployment
The previous two errors were solved, but I got three(!) new ones instead :
com.google.appengine.api.urlfetch — Cannot be resolved
dalvik.system — Cannot be resolved
twitter4j.internal.http.alternative — Cannot be resolved
Hmmm, that was not the result I was hoping for.
Now I had two options :
1. Finding out all the depedencies for dalvik, appengine etc, which you know will be a difficult route to take
2. Or getting to the bottom of it, and make it right with only the twitter4j dependency.
So I went for the second option :-)
After a number of searches, deployments and coffees I discovered that the three depedencies are actually optional and not needed.
You can specify this via this instruction in the <Import-Package>-element “;resolution:=optional”
And this did the trick, my bundle is set to “Resolved” and the twitter4j-api is working inside WEM/CQ!