[SOLVED] Openhab-core + maven/bnd addon

Hey developer community,

I’m feeling a bit lost with maven/bnd on eclipse/bndtools. The tutorial on https://bndtools.org/tutorial.html is unfortunately outdated.

I like to archive the following:

  1. Having openhab-core in my eclipse workspace, as well as a maven/bnd project: Works
  2. Start a bndrun file (for example the demo one), and add my maven/bnd project bundle or any other eclipse workspace maven/bnd project bundles to it: No idea

I know how to handle this with Gradle and eclipse/buildship, but in that case the bndrun file is generated. So how do I go forward with an existing bndrun file?

What I have done so far in eclipse

  • Right click on my maven/bnd project and add the bnd nature (in this case for demo purposes the astro binding)
  • Modify the demo bndrun file:
-runrequires: \
 ...
 bnd.identity;id='org.openhab.binding.astro',\
 ...

-runbundles: \
 ...
 org.openhab.binding.astro;version='[2.5.0,2.5.1)',\
 ...

Resolving the bndrun file fails with org.hamcrest not available. But I have probably not done it in the correct eclipse/bndtools way I guess.

Cheers, David

David, have you tried adding it through the console?

I can probably just add the jar file to the runtime directory and karaf will resolve and load it. But that doesn’t help with debugging does it? And it doesn’t auto-reload the bundle on changes within eclipse without that additional copy file step.

No, this won’t help with debugging, but you hadn’t mentioned that was a requirement :slightly_smiling_face:. The IDE is not using Karaf, so it will be slightly different than what you are used to. I’ve added bundles directly from the target directories… never copied to runtime.

Did you look at https://github.com/maggu2810/openhab-demo? This gives me at least a running OH in Eclipse, I didn’t manage to add my own bundles, but only looked at it for a minute or so. Maybe that is a point to start with.

Thanks for the link. The original openhab-core repo works since a few days though. You can start and debug core bundles from within the ide.

But I have not the slightest idea on how to add another bundle to the bnd workspace which to my understanding is a prerequisite to add it to the bndrun file. @maggu2810, do you have a helping link or a few minutes?

Thanks

We are not using the Bnd workspace or Bnd natures.
We are using Maven + Bnd.
I assume the tutorial
So, do not add the the Bnd nature.

If you would like to learn more about it try to read the enRoute tutorials and documentation.

IIRC I read in this community that tests are not working inside the IDE or debugging is not working.
This is not correct!
Perhaps it does not that way the people think it should work. :wink:

So, let’s assume you are using openHAB Core and my openhab-demo branch (imported in the IDE) – what are you missing?

You can open the POM of my demo app (openhab-demo) and add further dependencies.
This dependencies should then be part of bundles you can add.
After all is done you need to resolve the app and you can start and debug it.

The resolving itself will not work as intendet as long as the DS requirements are disabled.
So, you should perhaps always cherry-pick https://github.com/maggu2810/openhab-core/commit/4253e1428e79acde4080a1ea74d6853372973942

Ah ok. Now I understood. I’m not using any of the bnd UI stuff (except the resolve button maybe) in eclipse.

I’m using plain maven dependencies, like with gradle and bnd resolve will find those bundles.

Is the eclipse maven combo smart enough to find dependencies in my eclipse workspace instead of online resolving them?

I forgot to mention that, I did apply that change of course

AFAIK with 4.2 (perhaps 4.1, too) if a Maven coordinate is part of your workspace, that one will be used.
But you need to check it yourself.

Works. The workspace bundle is preferred.

For new contributors it need to be easier or better documented of course.

But I guess as soon as we have converted all openhab2-addon projects and the distro, we have a demo bndrun file that can resolve all those addon bundles and the new contributor can basically drag&drop within the bnd UI eclipse interface.

Cheers, David

It would be awesome to have a video showing how to setup Eclipse to develop bindings “the new way”.
Old video (https://www.youtube.com/watch?v=o2QjCGdZl7s) is outdated.

I run openHAB on Raspberry PI, so I’d me happy to know more how to debug code on my Raspberry - develop on PC< then run on Raspberry and get breakpoints on PC (is this possible? :slight_smile: )

Hi!
Not much of a video, but maybe it could be for some help,

//Basse

I’ve tried that but had no luck - Need some help with setup to create new binding using maven/bnd

I’m getting errors all the time.

I’ve cloned demo repo and opened it in eclipse. By that I mean:
I’ve started eclipse and imported maven project into package explorer. I’ve picked the directory where I cloned demo repo.
I’m new to Java so maybe I’m doing this step wrong. How should I open demo folder in eclipse?

Hi!
I see that the link you refers to is another one as I described, Please have a look in this one.
There are a lot of advises which helped me to get my system working.
//Basse

I’ve done all those steps:

  1. Install Bndtools in your Eclipse IDE. (Is automatically installed if you have used the Eclipse Installer for openHAB development.) easy one
  2. Checkout the bnd based openHAB demo application: git clone --depth=1 https://github.com/maggu2810/openhab-demo . also easy
  3. Open the directory in Eclipse. Wait for the download and build to finish (about 3-5 minutes). this gives me errors

how do I “open the directory in Eclipse”? What options should I choose?
Should I import maven project into packages?

I do need some advice here too,
I read somewhere that you should not use(install) openhab2-addons, is this still true?
If it is possible might it be necessary to rewrite these steps.

Any way this is how I have done the installation, (about not to install openhab-2 addons is not described in the steps you follow, sorry for that).
So I have just let Step 3. Open the directory… and Step 4. Checkout… and Step 5. In Eclipse… be.

Then Step 6. ++

Regarding Step 7b are there some warnings during the installation but at the very end is it in my case as:
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:20 min
[INFO] Finished at: 2019-04-02T13:53:14+02:00
[INFO] ------------------------------------------------------------------------

//Basse

I’ve tried with and without openhab-2 addons installer.

I have question about step 3. How to open that directory in Eclipse? Using import-> General or Import->Maven? or should I do it in other way?

Both should work, I’d use Import maven.
But as I said, the demo package might not work without annoyances at the moment.

I have opened an Issue: https://github.com/maggu2810/openhab-demo/issues/1
But it works for Markus, so no further idea.

Because there happend recent fixes. What you can do is to let maven/bnd re-resolve as Markus did in that mentioned issue.

On the command line: maven -DwithResolver
In Eclipse: Context menu in the package explorer on the demo project -> Maven -> Select Maven profile

I’ve opened Eclipse, created a new workspace, in package explorer I choose Import>Maven->Existing Maven Projects, then I selected folder to which I cloned https://github.com/maggu2810/openhab-demo.
According to instructions this project should build after a while, but in my case, all I got are these errors:

Tomorrow I’ll try on different PC with a fresh install of Eclipse.