Karaf: add addon-jar and install dependancies

Dear Community,

I try to activate an addon manually. I went to the openhab2-addons folder and did a maven build of the russound addon. It went fine - the build was successful!

I placed to corresponding jar-file into the runtime folder and activated the new discovered addon by typing “bundle:start 235”. Afterwards I got an exception, here

openhab> bundle:start 235
Error executing command: Error executing command on bundles:
Error starting bundle 235: Could not resolve module: org.openhab.binding.russound [235]
Unresolved requirement: Import-Package: com.google.gson; version="[2.8.0,3.0.0)"

It seems that I need to install the dependancies before I can successfully start the addon.

How do I get this done? Is there an opportunity to deal with dependancies efficiently - it seems pretty inefficient to do this manually. Thanks in advance for your reply.

Best regards,
Jochen

If you copy an addon into the addons directory, Karaf can’t/won’t resolve the dependencies for you, so you need to add them manually. Rather than copying the addon to addons, if you do a bundle:install <URL to jar>, Karaf will resolve the dependencies for it. I don’t see why the addons directory watcher mechanism couldn’t be setup to do this.

Thanks for your answer, Scott. Please help me clarifying things here, a little bit more.

  1. “Karaf can’t/won’t resolve the dependencies for you, so you need to add them manually.” - Ok, so you second my statement.

  2. “Rather than copying the addon to addons, if you do a bundle:install <URL to jar> …” , …Ok, but there is no url to my created jar for the addon or do you mean that I should install depbendancy by dependancy by calling “bundle:install …”. It’ll be great if you can add one or two shell commands related to your advice, because than it is more clear for me, what to do with your advice.

Cheers,
Jochen

The url can be a path… bundle:install file:///my_new_jar (might need quotes around the url).

OK, I tried to install the bundle via mvn

236 | Installed | 80 | 2.5.0.201906281928 | openHAB Add-ons :: Bundles :: Russound Binding
openhab> bundle:start 236
Error executing command: Error executing command on bundles:
Error starting bundle 236: Could not resolve module: org.openhab.binding.russound [236]
Unresolved requirement: Import-Package: com.google.gson; version="[2.8.0,3.0.0)"

openhab> bundle:install https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.0/gson-2.8.0.jar
Bundle IDs:
Error executing command: Error installing bundles:
Unable to install bundle https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.0/gson-2.8.0.jar: org.osgi.framework.BundleException: Error reading bundle content.
openhab> bundle:install http://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.0/gson-2.8.0.jar
Bundle IDs:
Error executing command: Error installing bundles:
Unable to install bundle http://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.0/gson-2.8.0.jar: org.osgi.framework.BundleException: Error occurred installing a bundle.
openhab>

Delete the jar and uninstall russound (may need to clear cache). Use bundle:install to install russound (not it’s dependencies). I think Karaf will then resolve it’s dependencies.

Your gson jar file path seems to incorrect. Following should work (at least)

bundle:install http://central.maven.org/maven2/com/google/code/gson/gson/2.8.5/gson-2.8.5.jar

When you install jar files manually, the dependencies are not automatically solved, so you need to install them manually as well. Karaf feature resolves and installs all bundles, configurations, and dependency features described in the feature file.

Alternatively you build a .kar file instead of a .jar file which contains all osgi dependency information. A .jar file doesn’t.

Great - I was able to activate the bundle.

Anyway, I got no idea, how you found out about the correct URL?

Dear David,

where do I find some information, how to do that for openHAB? I have searched for it on the internet, but it was not possible to find an openHAB-related useful thread.

Thanks for this hint. In my opinion this is a great idea - what do you think about adding such a section to add to the openHAB-docs?

Best regards,
Jochen

kar files defeat the purpose of reusing dependencies across different bindings. They are only useful for development purposes and to share to other users for testing.

I think that’s why they are nowhere documented to not encourage anyone to “overuse” them (eg distribute kar files on their own, circumventing the entire openhab2-addons and maintenance review system). openHAB relies on reviewed addons. There is no addon isolation or permissions system in place.