# VS Code debugger ignores code changes

**URL:** <https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755>\
**Category:** IDE & Build\
**Tags:** vscode\
**Created:** [May 24, 2021, 6:38pm UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755 "2021-05-24T18:38:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sheldon](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sheldon](https://community.openhab.org/u/sheldon)\
**Post date:** [May 24, 2021, 6:38pm UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/1 "2021-05-24T18:38:09Z")

</div>

In order to fix a bug in a binding (not my own binding) I set up VS Code as an IDE in Windows 10 closely following this very helpful [guide](https://www.openhab.org/docs/developer/ide/vscode.html). Everything works fine at first. I can attach to the local openHAB instance and debug the code.

However, after making changes, recompiling and copying the JAR file to the addon folder (by hitting F5), the changes are not applied and the debugger still uses an old (cached) version ignoring the new code in the (updated) source file.

I already tried deleting JAR files from Maven’s .m2 repository and the addons folder of the openHAB instance as well as the contents of the cache and tmp folders in the userdata folder of the openHAB instance, but to no avail.

I would be grateful for any hint on how to make the VS Code debugger for Java use the updated code.

---

<div class="post-metadata">

**Author:** ![pacive](https://community.openhab.org/user_avatar/community.openhab.org/pacive/32/36234_2.png) [@pacive](https://community.openhab.org/u/pacive)\
**Post date:** [May 25, 2021, 4:32am UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/2 "2021-05-25T04:32:40Z")

</div>

Are you sure that the new jar is loaded correctly? Log in to the karaf console of the OH instance and use bundle:list to check, the version number of the bundle should include a timestamp of when it was built. Also note that it might take a couple of seconds before the jar is loaded after you put it in the addons folder.

---

<div class="post-metadata">

**Author:** ![sheldon](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sheldon](https://community.openhab.org/u/sheldon)\
**Post date:** [May 25, 2021, 5:53am UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/3 "2021-05-25T05:53:03Z")

</div>

Thank you for the hint. Yes, the build date suggests that the JAR is loaded correctly. However, I noticed that this is the only file that has the state “Installed” and not “Resolved”. I don’t know what that means.

 ![build_list](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/9/3/93ff7c92d4414edda716644fb05c8bb0e8de64fa.png)  
So it looks like it is compiling the “wrong” code, using the original code from the repository instead of my own code. I started from scatch several times (by fully deleting the openHAB instance and the git repository), making the changes **before** the first build, but it still uses the original code judging from the line numbers in the call stack.

---

<div class="post-metadata">

**Author:** ![pacive](https://community.openhab.org/user_avatar/community.openhab.org/pacive/32/36234_2.png) [@pacive](https://community.openhab.org/u/pacive)\
**Post date:** [May 25, 2021, 6:32am UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/4 "2021-05-25T06:32:13Z")

</div>

Haven’t used VSCode for this, but when using IntelliJ, I usually start OH manually using start\_debug.bat and then attach the debugger to that running instance. Would this be possible here? (just skip the “`CTRL-SHIFT-P -> Tasks: Run Task -> Start openHAB (Debug)`” step since it’s already running). You would then get a separate console window already logged into karaf where you can check if all bundles are started correctly.

---

<div class="post-metadata">

**Author:** ![sheldon](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sheldon](https://community.openhab.org/u/sheldon)\
**Post date:** [May 25, 2021, 7:08am UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/5 "2021-05-25T07:08:35Z")

</div>

Thanks for the hint. The initial snapshot was taken after I uninstalled the binding in the Web UI (sorry, I forgot). After reinstalling the binding in the Web UI, I have two (active) JAR files:

 ![build_list_duplicate](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/a/a/aa87268207d003b9f26db18eea4a27f6359e7580.png)  
That was my presumption from the beginning, and your suggestion helped to prove it.  
But how can I use “my” binding without installing the original binding in the Web UI? Reading the [documenation](https://www.openhab.org/docs/developer/ide/eclipse.html) for the Eclipse IDE, it looks like I might need to edit the POM file to make the build with the integrated binding (i.e. without the need to install it in the Web UI). Alternatively, how can I install the binding from my own JAR file?

---

<div class="post-metadata">

**Author:** ![glhopital](https://community.openhab.org/user_avatar/community.openhab.org/glhopital/32/91632_2.png) [@glhopital](https://community.openhab.org/u/glhopital)\
**Post date:** [May 25, 2021, 8:53am UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/6 "2021-05-25T08:53:10Z")

</div>

Ensure that version number in the pom file of your binding is aligned with version number of the demo app (should be 3.1-snapshot I presume). If it’s not the case, you’ll be provided with current existing version, not the one you’re working on.

---

<div class="post-metadata">

**Author:** ![sheldon](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sheldon](https://community.openhab.org/u/sheldon)\
**Post date:** [May 25, 2021, 9:09am UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/7 "2021-05-25T09:09:17Z")

</div>

I checked the POM file in the root directory of the binding, and the version number seems to be correct:

```yaml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.openhab.addons.bundles</groupId>
    <artifactId>org.openhab.addons.reactor.bundles</artifactId>
    <version>3.1.0-SNAPSHOT</version>
  </parent>

  <artifactId>org.openhab.binding.enocean</artifactId>

  <name>openHAB Add-ons :: Bundles :: EnOcean Binding</name>

</project>

```

To my knowledge there is no demo app for VS Code (or I haven’t found it yet). The debugger just attaches to a running debug instance of openHAB (which is 3.1.0-SNAPSHOT as well).

---

<div class="post-metadata">

**Author:** ![glhopital](https://community.openhab.org/user_avatar/community.openhab.org/glhopital/32/91632_2.png) [@glhopital](https://community.openhab.org/u/glhopital)\
**Post date:** [May 25, 2021, 9:30am UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/8 "2021-05-25T09:30:16Z")

</div>

You’re right, I did not realize you were using VS Code. Too bad. I’m not used to this environment at all. Sorry, I can’t help further.

---

<div class="post-metadata">

**Author:** ![pacive](https://community.openhab.org/user_avatar/community.openhab.org/pacive/32/36234_2.png) [@pacive](https://community.openhab.org/u/pacive)\
**Post date:** [May 25, 2021, 10:49am UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/9 "2021-05-25T10:49:56Z")

</div>

You shouldn’t need to install it via the UI, but for some bindings that might be a method to ensure all dependencies are installed (after that the binding should be uninstalled again). Only the binding in the addons-folder should be installed, and putting the jar in that folder should be enough to load it. The only steps I usually need to take is:

1. Start an OH instance in debug mode (start\_debug.bat)
2. Build the addon (`mvn clean install` in the bundle directory, or via the IntelliJ UI)
3. Attach the debugger
4. Copy or move the jar to the addons directory

There might initially be some error messages from the debugger complaining that the bytecode doesn’t match the source code, this is because an old version of the binding is still loaded, but after a few seconds that is disposed and the new version is loaded instead which has the correct byte code.

Try running these steps manually and see if it works better. You might need to edit the launch.json file and comment out the `preLaunchTask` line to prevent VSCode from building the jar (not sure if other things might need to be changed as well).

---

<div class="post-metadata">

**Author:** ![sheldon](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sheldon](https://community.openhab.org/u/sheldon)\
**Post date:** [May 25, 2021, 2:14pm UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/10 "2021-05-25T14:14:46Z")

</div>

Thank you very much for these helpful instructions. The EnOcean binding uses a serial gateway and thus depends on the module `org.openhab.core.config.discovery.usbserial`. Unfortunately, uninstalling the binding in the Web UI seems to remove that module as well. After removing the binding, the log shows messages like the following:

```auto
16:05:05.435 [WARN] [org.apache.felix.fileinstall] - Error while starting bundle: file:/C:/Users/Dietmar/openhab/addons/org.openhab.binding.enocean-3.1.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.enocean [235]
  Unresolved requirement: Import-Package: org.openhab.core.config.discovery.usbserial

```

How can I manually add dependencies (in this case `usbserial`)?

---

<div class="post-metadata">

**Author:** ![pacive](https://community.openhab.org/user_avatar/community.openhab.org/pacive/32/36234_2.png) [@pacive](https://community.openhab.org/u/pacive)\
**Post date:** [May 25, 2021, 2:49pm UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/11 "2021-05-25T14:49:19Z")

</div>

Try running `feature:install openhab-transport-serial`, I think that should be the only required bundle, but might be others are needed as well

---

<div class="post-metadata">

**Author:** ![sheldon](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sheldon](https://community.openhab.org/u/sheldon)\
**Post date:** [May 25, 2021, 8:25pm UTC](https://community.openhab.org/t/vs-code-debugger-ignores-code-changes/122755/12 "2021-05-25T20:25:27Z")

</div>

@pacive: Thank you very much indeed for your support! I managed to apply the changes following your suggestions. And I seem to have fixed the bug as well. 😃

I would suggest to add these recommendations (i.e. not to install bindings using the Web UI and to install potential dependencies using the console) to the VS code documentation.
