# Amending existing binding code - what is the "right" way to install it?

**URL:** <https://community.openhab.org/t/amending-existing-binding-code-what-is-the-right-way-to-install-it/145930>\
**Category:** Add-ons\
**Created:** [April 9, 2023, 11:11am UTC](https://community.openhab.org/t/amending-existing-binding-code-what-is-the-right-way-to-install-it/145930 "2023-04-09T11:11:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![PrzemoF](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/41988e/32.png) [@PrzemoF](https://community.openhab.org/u/PrzemoF)\
**Post date:** [April 9, 2023, 11:11am UTC](https://community.openhab.org/t/amending-existing-binding-code-what-is-the-right-way-to-install-it/145930/1 "2023-04-09T11:11:10Z")

</div>

I’m working on [changes to denonmarantz binding](https://community.openhab.org/t/denon-binding-for-dra-100-amend-exisitng-or-make-a-new-binding/145862/5) but I’m struggling to find in documentation what’s the best way to develop code in an existing binding.

My setup: openHAB installed on raspbian on raspberry pi, so there is a kar file in the system with all add-ons, including the one I’m trying to improve. The system kar file is in /usr/share/openhab/addons/openhab-addons-3.4.2.kar. For code development I use vim+syntastic on a fedora linux (a separate machine)

What I did so far:

1. Cloned openhab-addons, modified and compiled the code, so I generated org.openhab.binding.denonmarantz-3.4.2.jar file.
2. Copied the file to /usr/share/openhab/addons/ on the raspbian/openhab machine.
3. Renamed jar to kar
4. I tried to install it with

```auto
kar:install file:///usr/share/openhab/addons/org.openhab.binding.denonmarantz-3.4.2.kar

```

or

```auto
install file:///usr/share/openhab/addons/org.openhab.binding.denonmarantz-3.4.2.kar

```

The commands doesn’t generate any output or errors, but nothing seems to be changing in the system.  
I don’t see any new binding.

Now the question: how can I install the modified extension? Should I change the version for the modified binding? Change the name? Create a copy with a new name?

There is definitely something obvious that I’m missing. Any advice or hint how to proceed would be welcome!

P.S. [I read about setting the IDE](https://www.openhab.org/docs/developer/#develop-a-new-binding) but it doesn’t say how to install the developed code. Maybe Eclipse does that part, but I prefer simple bulletproof tools.

---

<div class="post-metadata">

**Author:** ![splatch](https://community.openhab.org/user_avatar/community.openhab.org/splatch/32/33925_2.png) [@splatch](https://community.openhab.org/u/splatch)\
**Post date:** [April 9, 2023, 11:21am UTC](https://community.openhab.org/t/amending-existing-binding-code-what-is-the-right-way-to-install-it/145930/2 "2023-04-09T11:21:22Z")

</div>

Updating existing binding can go in selective way. If you have a build which does not change dependencies then:

```auto
openhab> la -s|grep -i astro
286 | Active | 80 x 3.0.2 | org.openhab.binding.astro
openhab> update 286 file:/some/file/in/my/filesystem/created-by-me.jar
openhab> la -l|grep -i astro
286 | Active | 80 x 3.0.2 | file:/some/file/in/my/filesystem/created-by-me.jar

```

Above way updates just sinlge line. Command in line 1 allows to find module id (286 in above example). The `update` call in third line tells to load another file for that module. Command in fourth line confirms that updated location is accepted. You can notice that there are two switches `-s` which prints module name and `-l` which prints its update location.

Update location is retained across restarts, so subsequent updates can be done with `update 286`. You need to specify update location only if you change it.

---

<div class="post-metadata">

**Author:** ![PrzemoF](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/41988e/32.png) [@PrzemoF](https://community.openhab.org/u/PrzemoF)\
**Post date:** [April 9, 2023, 12:13pm UTC](https://community.openhab.org/t/amending-existing-binding-code-what-is-the-right-way-to-install-it/145930/3 "2023-04-09T12:13:19Z")

</div>

Thanks! I t works slightly different for me - I’ll provide a detailed info later on (file path is not shown after installation).

---

<div class="post-metadata">

**Author:** ![jimtng](https://community.openhab.org/user_avatar/community.openhab.org/jimtng/32/98543_2.png) [@jimtng](https://community.openhab.org/u/jimtng)\
**Post date:** [April 9, 2023, 12:30pm UTC](https://community.openhab.org/t/amending-existing-binding-code-what-is-the-right-way-to-install-it/145930/4 "2023-04-09T12:30:10Z")

</div>

> [@splatch](#):
>
> Update location is retained across restarts, so subsequent updates can be done with `update 286`.

This is very handy to know.

1. If you updated the jar file, do you need to call update again? Won’t it detect the changes automatically?

2. How can we revert back to the original binding / jar?

---

<div class="post-metadata">

**Author:** ![PrzemoF](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/41988e/32.png) [@PrzemoF](https://community.openhab.org/u/PrzemoF)\
**Post date:** [April 9, 2023, 1:49pm UTC](https://community.openhab.org/t/amending-existing-binding-code-what-is-the-right-way-to-install-it/145930/5 "2023-04-09T13:49:21Z")

</div>

Thanks for help Łukasz! I have a first working version of the amended denonmatantz binding 🤓  
Lessons learned:

1. la is the same as bundle:list
2. to point to a file one had to use file:// prefix
3. no need to rename jar to kar
4. diag can help with diagnosing problems with binding installation
5. if you get bundle status other than Active it probably makes sense to remove is (from GUI), install again (form GUI) and then update the modified version on top of it.
6. Once the setup is fixed the process of developing (code change, compile, deploy) takes a few seconds. I use scp to copy the file over the the openhab machine.

---

<div class="post-metadata">

**Author:** ![splatch](https://community.openhab.org/user_avatar/community.openhab.org/splatch/32/33925_2.png) [@splatch](https://community.openhab.org/u/splatch)\
**Post date:** [April 9, 2023, 9:45pm UTC](https://community.openhab.org/t/amending-existing-binding-code-what-is-the-right-way-to-install-it/145930/6 "2023-04-09T21:45:56Z")

</div>

> [@jimtng](#):
>
> This is very handy to know.
> 
> 1. If you updated the jar file, do you need to call update again? Won’t it detect the changes automatically?
> 2. How can we revert back to the original binding / jar?

Each call of `update` command copies contents of referenced file into `userdata/cache` directory. As long as you do not do a “clean” start of openHAB you do not need to worry about reset. Also update of file does not affect contents of storage directory, unless you call update again.  
In order to revert to previously known state you can do `update xyz mvn:org.openhab.addons/abc/version`. This will simply fetch a abc module from runtime/system directory.  
Long story short - when you download openHAB you have copy of everything in runtime/system directory. When you launch it for first time its size almost doubles, cause major part of runtime contents gets copied to userdata/cache to retain actual runtime state.

---

<div class="post-metadata">

**Author:** ![PrzemoF](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/41988e/32.png) [@PrzemoF](https://community.openhab.org/u/PrzemoF)\
**Post date:** [August 1, 2023, 7:30pm UTC](https://community.openhab.org/t/amending-existing-binding-code-what-is-the-right-way-to-install-it/145930/7 "2023-08-01T19:30:15Z")

</div>

For future use:  
My setup: a laptop for coding & compiling, rpi running openHUB.

1. git clone [GitHub - openhab/openhab-addons: Add-ons for openHAB](https://github.com/openhab/openhab-addons.git)
2. find the binding to work on, in my case it’s in openhab-addons/bundles/org.openhab.binding.denonmarantz
3. compile the binding without any code changes to make sure the compilation works OK

```auto
mvn clean install -pl :org.openhab.binding.denonmarantz

```

1. On compiling errors first check java --version and mvn --version and make sure it’s all OK with the versions
2. Make changes or apply patches
3. Compile again
4. Successful compilation producer jar file in the target directory. In my case in openhab-addons/bundles/org.openhab.binding.denonmarantz/target and the file is called org.openhab.binding.denonmarantz-4.1.0-SNAPSHOT.jar
5. Transfer the file to the hardware running openhab to /usr/share/openhab/addons/ (on raspbian)  
9 Change the ownership of the file with

```auto
sudo chown openhab:openhab org.openhab.binding.denonmarantz-4.1.0-SNAPSHOT.jar

```

1. log in openHAB console with `ssh -p 8101 openhab@localhost`
2. search for the binding:

```auto
openhab> la -s|grep -i denonmarantz
237 │ Active │ 80 │ 4.0.1 │ org.openhab.binding.denonmarantz
245 │ Active │ 80 │ 4.1.0.202308011911 │ org.openhab.binding.denonmarantz

```

1. check the files (one is the original one, one is modified):

```auto
openhab> la -l|grep -i denonmarantz
237 │ Active │ 80 │ 4.0.1 │ mvn:org.openhab.addons.bundles/org.openhab.binding.denonmarantz/4.0.1
245 │ Active │ 80 │ 4.1.0.202308011911 │ file:/usr/share/openhab/addons/org.openhab.binding.denonmarantz-4.1.0-SNAPSHOT.jar

```

13 Uninstall the original binding and check it’s removed:

```auto
openhab> uninstall 237
openhab> la -s|grep -i denonmarantz
245 │ Active │ 80 │ 4.1.0.202308011911 │ org.openhab.binding.denonmarantz
openhab> la -l|grep -i denonmarantz                                                                                                                                                           
245 │ Active │ 80 │ 4.1.0.202308011911 │ file:/usr/share/openhab/addons/org.openhab.binding.denonmarantz-4.1.0-SNAPSHOT.jar

```

1. I run update (looks like OH3 might behave in a different way than OH4:

```auto
update 245 file:/usr/share/openhab/addons/org.openhab.binding.denonmarantz-4.1.0-SNAPSHOT.jar

```

1. Enjoy!
