Tutorial: Migrate your binding to the Maven + Bnd based build system

ok. I think I know what is happening. The root project has no .project in git. So anyone importing it can be give it any name without having a conflict with Git. I assume you imported that project once, or maybe it’s already an older project that still was there for a long time but remained there because it’s not in git. Now this project you have is named org.openhab.binding.zigbee in the Eclipse (.project file). This name conflicts with the name of the sub project that has the same name, and therefor can’t be imported. Well this is what I could think of on how you have that name for the root project.

I imported all projects using Import -> Maven -> Existing Maven Projects and then the root project imports as org.openhab.addons.zigbee.reactor.

Thanks. I tried removing the removing all projects from the IDE, then closing the IDE and deleting the project file in that folder, then opening the IDE and reimporting all the files - it still doesn’t give me the reactor project…

I might have found the issue - it might be the name of the folder I have the zigbee projects in. It is org.openhab.binding.zigbee (as per the project name on GH). I’ve now renamed this to openhab-zigbee and this project seems to be the reactor. Now if I look at the parent of the POM (in MacOS by holding down command key and clicking on the parent in the pom) I now see the right version at least, so maybe this is progress.

Unfortunately though, now the runtime won’t run at all - I get a fatal runtime error when running the demo app and no cleaning etc seems to resolve it!

It might be time for a complete reinstall of the IDE again I suspect :(.

I have the same name for that folder and have no problem getting the reactor file. Did you import as Existing Maven projects?

Yes.

Anyway, I now can’t get anything to work - the runtime is just crashing as soon as I try and run demoapp.

Welcome to Apache Felix Gogo

g! #
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fff5e316d09, pid=18759, tid=0x0000000000002603
#
# JRE version: Java(TM) SE Runtime Environment (8.0_221-b11) (build 1.8.0_221-b11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.221-b11 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C  [libsystem_platform.dylib+0x1d09]  _platform_memmove$VARIANT$Haswell+0x29
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#

I can’t seem to recover from this so far.

Ouch :frowning_face: Is this openJDK? It’s seem a bit less stable with developing in combination with this runtime environment. I’ve seen some crashes with openJDK, but only with I changed code while it’s running. It didn’t like hot code replacements. Not cases where I couldn’t run at all.

I assuming it did work with 1.2.3? You might try with that version again. Just to confirm it’s not specific to the new version 1.2.6.

I tried this a few more times - what ever name I give the folder is what the reactor project is called. If it is org.openhab.binding.zigbee, then this conflicts with the inner project of the same name and the project is not imported. What OS are you using? Maybe this is a MAC issue with how the projects get named?

However, unfortunately though after reinstalling the IDE I still have the above fatal error so something else is majorly broken.

It should be fine - I’m running other projects with 1.2.6. I’ll see if I can switch back - now that I’ve renamed the folder I need to reconfigure my git IDE as well…

No - it’s Oracle.

Which eclipse version are you running’

The latest (2019-09).

It’s getting late here. So I’ll check tomorrow with that version (I was now using version 2019-3, but have several installations, so will check with that specific version.) I’m running Ubuntu. But I wouldn’t expect that to make a difference.

1 Like

Thanks.

After much cleaning, running maven and clearing the p2 cache, I’ve got things running again at least. With the change of folder name it now seems to resolve the correctly.

I’m not convinced - I couldn’t get it to change names with the folder named as it was, but I shan’t be experimenting further as I’ve already spent most of the weekend trying to get this working.

Good tutorial. In https://www.openhab.org/docs/developer/buildsystem.html#adding-dependencies, it mentions about putting all relevant lib files into /lib, where exactly is this with relative to the bundle root? Is it in src/main/resources/lib? or same lvel as src?

It’s in the bundle root itself, so next to src

2 Likes

Let’s say i need to use “org.openhab.core.io.transport.mqtt” in my custom bundle, but during “Resolve” on app.bndrun, i am getting this error:

osgi.wiring.package: (&(osgi.wiring.package=com.hivemq.client.mqtt.datatypes)(&(version>=1.1.0)(!(version>=2.0.0))))
⇒ [com.hivemq.client.mqtt version=1.1.2]
⇒ osgi.wiring.package: (&(osgi.wiring.package=dagger))
how do i attach this “dagger” package into my custom bundle in order to have a successful “Resolve”? I tried Step 8, but still can’t get through this problem.

Cheers

I still don’t understand why the folder name is used as project name and not the artifact id.
Anyway I tried Eclipse 2019-9 and it worked the same for me as 2019-3. So it might be a mac thing, or just some specific option we use differently. Hopefully you won’t experience problems anymore.

Without knowing how your feature.xml and poms look like I would be guessing. So I don’t know the answer other than look at the other bindings that use mqtt io.

Sure. Even org.openhab.binding.mqtt have the similar problem. Here are my POM.xml and features.xml.

POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" 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>2.5.0-SNAPSHOT</version>
  </parent>

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

  <name>openHAB Add-ons :: Bundles :: TestMQTT Binding</name>
  <dependencies>
	<dependency>
	    <groupId>com.google.dagger</groupId>
	    <artifactId>dagger</artifactId>
	    <version>2.0</version>
	</dependency>
  </dependencies>
</project>

feature.xml

<?xml version="1.0" encoding="UTF-8"?> mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${project.version}/xml/features
<feature name="openhab-binding-testmqtt" description="TestMQTT Binding" version="${project.version}">
    <feature>openhab-runtime-base</feature>
    <bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.testmqtt/${project.version}</bundle>
    <bundle dependency="true">mvn:com.google.dagger/dagger/2.0</bundle>
</feature>

@hilbrand This has also been discussed on another thread (struggling-with-mqtt-in-development-of-new-binding). @J-N-K is aware of it, but has no time to look into it, which I fully understand.
A released binding affected by it is the nikohomecontrol binding. I did some further development, but can’t get it to run inside Eclipse anymore since the move to HiveMQ. I tried doing remote debugging, but for a reason I don’t understand yet, Eclipse does not connect to the locally running OH instance on my Windows laptop.
The binding compiles fine and I can run it in an OH install, just not debug at this time.
If you have any suggestions, I would very much appreciate it.

@hilbrand i tried to follow your guide with regards to external libraries. My bundle has several dependencies in POM and FEATURE:

The bundle works on Eclipse IDE debug but fail to resolve on snapshot 2.5.0 because of missing of above libraries. I thought with these definitions that will be downloaded automatically by Karaf? Thanks

<dependency>
      <groupId>org.openhab.osgiify</groupId>
      <artifactId>io.socket.socket.io-client</artifactId>
       <version>1.0.0</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>org.openhab.osgiify</groupId>
       <artifactId>io.socket.engine.io-client</artifactId>
      <version>1.0.0</version>
      <scope>compile</scope>
   </dependency>
  	<!-- https://mvnrepository.com/artifact/javax.websocket/javax.websocket-api -->
     <dependency>
 	    <groupId>javax.websocket</groupId>
    <artifactId>javax.websocket-api</artifactId>
 	    <version>1.1</version>         
   <scope>provided</scope>
    </dependency>

Q1) Can someone explain how to to use libraries in .m2/repository? Assume that i want to use websocket-server.jar, how do i define this in my binding and also openhab.demo.app? By doing this, do i still have to manually this websocket-server.jar into “/add-ons” folder of openhab-distro in another system?

Q2) I see that “https://openhab.jfrog.io/openhab/libs-release” repository has many libs in there, how do i force IDE or openhab-distro to automatically pull those libs?

Sorry, i am not really 100% with this maven or bnd in openhab. Cheers