Beginners Guide to create an Addon without the Eclipse IDE for openHAB 2.4 and place it in your running openHAB runtime

Dear Community,

In this thread I will try to enable people to develop their addons without the current unstable Eclipse IDE for OH 2.5. Feel free to add some links to relevant articles. Thanks in advance for your help.

Current question: Does it make sense to avoid Eclipse here and use Visual Studio Code? The creation of the jar will be done without Eclipse anyway. What is the most comfortable way in your opinion?

Approach with current Eclipse IDE for openHAB: see https://github.com/openhab/openhab2-addons

Best regards,
Jochen

@tmrobert8 has already written a development tutorial for setting up VS Code for development (see https://www.openhab.org/docs/developer/ide/vscode.html). Are you proposing something different or extending that tutorial?

1 Like

IMHO it should be possible to create a new addon without the help of any IDE. ie do it from a command line.
A beginnerā€™s guide would explain whatā€™s happening in each step. Then there would be links to corresponding guides for doing the same thing in different IDEs, explaining how the IDE is doing some of the work for you that you did manually before.
It would be written is such a a way that it us useful for people like me who want to understand what is happening and also for those who donā€™t care any just want to get something running.
Iā€™d be happy to test and give you feedback anything you come up with.

Steve

But we do have that. Go to the addons2 repo and have a look at the readme. It explains how to build via command line.

If you follow the binding developer guide, it tells you everything you need to know about maven pom files, karaf feature files and whatnot. Those mechanisms are all IDE independent. And that is the huge difference to when I started with openHAB.

Two years ago, you were required to use the Eclipse Installer, you had no ideas what happened behind the scene (I was never able to get an already installed Eclipse ready for OH development) and you could only do certain actions from within the IDE. That is no more since the new buildsystem (bnd+maven). Of course that means that it is now more complicated within Eclipse to get development going.

We actually face a lot of problems with bnd+maven in combination with Eclipse (because the m2e maven 2 eclipse plugin is buggy as hell) and there is not much we can do. The plugin seems unmaintained.

Iā€™d love to start developing at least 2 bindings, Iā€™ve tried with the current docs and never get past even setting it all up.
A few tutorials, from a ā€˜hello worldā€™ beginner type step by step would be the way to go, the more people that can understand and get into making and improving bindings the better.

Examples of doing basic things would be a great addition such as:
how to retrieve a json from a cloud api
The best and easiest way to authenticate
How to auto discover items based on a json response
Etc etc
Forget all the error checking and what ifā€™s, once people start to understand the basics they will soon learn how to add this in after.

Guys,

you are great - thanks a lot for your hints to useful tutorials.

@rlkoshak:
I guess I will give it a try with VSCode and / or IntelliJ CE. Hopefully I do not need to extend anything, if all the necessary advice is still there.

@David_Graeff
I will go through the readme file. Itā€™ll be great if this works and all the people can understand this guide.

@delid4ve, @zephod:
Thanks for telling us, what your expectations and challenges were / are.

Best regards,
Jochen

Well, yes, there is a line that says ā€˜mvn clean installā€™ but that is a bit terse. What gets installed and where? What does install really mean? What if I want to run from the current directory to test local changes? How do you start the system once youā€™ve built it? etc, etcā€¦
This information is probably in the docs somewhere but its not easy to find.

Steve

1 Like

True, there is no exhaustive maven tutorial, the reason being that I have written a lot of those readme and developer files and I donā€™t understand Maven myself tbh. I prefer Gradle. Maven is doing too much behind the scenes and you canā€™t just look at a pom.xml file to know what will happen. Too much is done in maven via plugins, because maven canā€™t do much by itself. So you must know a dozen plugins and their maven goals and their behaviour and their quirkiness to get around. The command line interface feels like from the 90ths and Maven is way too verbose.

So I couldnā€™t write that tutorial because if it ever goes in my preferred direction, we will not use maven for long. Unfortunately a lot of other maintainers are still protecting Maven, because they are probably more familiar with Maven than Gradle.

Thatā€™s where it gets complicated. You canā€™t ā€œstartā€ OH easily. You need a full OSGi enviroment started before doing anything, then load required OH bundles and only then somehow inject your addons. Itā€™s not yet fully clear how to archive that easily for the IDEs or the command line.

Thanks for your answers.

I am trying to get the addon work done with VSCode. To achieve this I will implement a HelloWorld-Binding.

Anyway, is the script for the skeleton addon creation gone, which was available earlier?

Best regards,
Jochen

Still there under the bundles. BTW - let me know if you find any issues with the VSCode stuff I did. I tested on win but eyeballed the linux stuffā€¦

So - first errors on the build.

Iā€™ve setup VSCode on Windows 10. I created a new addon jobatest with the help of the skeleton script. I tried to use mvn clean install -DskipChecks and got the following errors, that the import org.eclipse was not able to be resolve the import of org.eclipse ā€¦

I guess I need to configure VS Code appropriately - any advice what is missing in the corresponding docs: https://www.openhab.org/docs/developer/ide/vscode.html

Thanks in advance, what needs to be done in VSCode or die skeleton script, that the build can run as expected.

@ David_Graeff
I donā€™t know, call me crazy, but I would have thought clear directions on how to ā€œstartā€ OH from the command line is fairly important and would be fully documented by now. I also would have thought that there would some kind of start script if it is that complicated.
I was poking around in the repos and I found a start.sh script in the openhab-distro repo that just calls bin/karaf. It looks like there needs to be some setup done to get bin/karaf to run. I also found a script called oh2_dir_layout but Iā€™ve run out of time now.
BTW I completely understand not wanting to spend time figuring out how something that you donā€™t believe in, ie maven, works. Perhaps you could wake up one of your fellow maintainers to help out here? I have a separate question on why mvn install works but mvn compile does not in the core repo.

Steve

The OH distro is nothing more than a Karaf with added repositories to find the add-ons and with all core bundles bundled. Starting OH means starting that Karaf instance.

But thatā€™s still not really possible in one command if you at the same time wanna debug a binding. There is also a group of maintainers that do not use karaf for developing, ie Kai. Because he is bundling the Eclipse setup file, that setup works different to what the story told in the documentation. Need to be resolved at some point.

@Jochen_Bauer: I have succesfully run the skeleton script from VS Code on W10, but on a Linux host (via the Remote-SSH VS Code extension). So I guess it is not the same scenario, only similar. Iā€™ve used @tmrobert8ā€™s tasks.json and launch.json with changed path settings to make the environment variables in tasks.json work on my Linux setup. Nothing moreā€¦

Did you already try a fresh start by clearing the Maven repository and as a first step, before running the skeleton, build an existing binding first (I mean run mvn clean install -DskipChecks on it)?

UPDATE: I was able to fire up the debugging batch script from VS Code.

1 Like

Hello @Jochen_Bauer ,

Iā€™m trying to make some local changes on Netatmo binding, but facing errors when I run ā€œmvn clean installā€. Iā€™m totally blocked and I cannot find a solution.
Could the issue be related with the migration of Netatmo binding to bnd? Do you know if is there is any guide to compile bindings with bnd?

Last commits on Netatmo binding are related to OSGi 3rd party libraries and Migration to bnd: https://github.com/openhab/openhab2-addons/tree/master/bundles/org.openhab.binding.netatmo

And an example of error Iā€™m getting:
Unable to resolve org.openhab.binding.netatmo/2.5.0.201907090725: missing requirement [org.openhab.binding.netatmo/2.5.0.201907090725] osgi.wiring.package; filter:="(osgi.wiring.package=android.net)"]]

Many thanks in advance.

Dear Daniel,

Unfortunately I am not able to help you here on this one. I guess in a few days or weeks I will get netatmo up and running too, so letā€™s see if itā€™ll work out for me. In the meatime, maybe another member can help?

Best regards,
Jochen

Anyone knows how to solve that the org.eclipse.xxx packages are not available when opening the addon folder of openHAB with VS code? Thanks in advance.

In my other addon, which builds by maven without any errors, there is a difference: under java dependencies there are all these jars listed, which seems to be non visible.

UPDATE: Oh no, after I tried to build the other addon, the build crashed and now the build of my addon which worked, breaks too - how can that happen?

UPDATE-2: after deleting maven cache under /usersā€¦/.m2/repositories/ the new build succeeded!

So the question is: why are the jars not visible in the freshly created addon skeleton? Iā€™ve run the windows create_skeletonā€¦ cmd file.

Thanks in advance.

Best regards,
Jochen