Thanks for the tip, about pom.xml, that was the key
And a question regarding that, I can see that ex. astro is not in org.openhab.demp.app/pom.xml and works anyway, but I had to add my own binding there to have it working, hm?
Anyway this is how I have my binding running: ( I have used the script
@hilbrand
has designed to rebuild the binding for bnd)
In Eclipe / File / Import… / Maven / Existing Maven Projects / ‘Chose binding and Add it to Bundles’
Restart Eclipe( Maybe Refresh will do ?)
In Tab app / Run, under Browse Repos, search for ‘binding’
Paste and copy org.openhab.binding.‘binding’ to Run Bundles
In Tab app / Source / look after -runbundles and Edit the line regarding ‘binding’ as: org.openhab.binding.‘binding’;version=’[2.5.0,2.5.1)’
In Tab app / Run should it be like: org.openhab.binding.‘binding’;version=’[2.5.0,2.5.1)’
Run OSGi
BR Basse
Basse_03:
And a question regarding that, I can see that ex. astro is not in org.openhab.demp.app/pom.xml and works anyway,
All bindings of openhab2-addons are automatically included, so they technically do not need to be in the pom.xml file. But if you read the “official” migration issue you see me adding astro anyway to get people used to the fact that you must add (your bindings) to the pom.xml file.
That is not required after the migration is done and some tweaks have been applied to openhab-core, but for now it is.
@David_Graeff
I have added two dependencies to demo project:
Now after restarting Windows, I get these errors when trying to Run OSGi:
Status ERROR: bndtools.core code=0 Cannot find /error/org.openhab.binding.astro;version=[2.5.0,2.5.1) Not found in [bndtools.m2e.MavenImplicitProjectRepository@52314f7f, bnd-cache [C:/Users/Tomek/.bnd/default-ws/cnf/cache/4.2.0/bnd-cache r/w=false], org.openhab.demo.app [C:\openhab\openhab-demo\app\target\tmp\resolve\app\cnf\cache\4.2.0\org.openhab.demo.app r/w=false]] null
Status ERROR: bndtools.core code=0 Cannot find /error/org.openhab.binding.pcf8574;version=[2.5.0,2.5.1) Not found in [bndtools.m2e.MavenImplicitProjectRepository@52314f7f, bnd-cache [C:/Users/Tomek/.bnd/default-ws/cnf/cache/4.2.0/bnd-cache r/w=false], org.openhab.demo.app [C:\openhab\openhab-demo\app\target\tmp\resolve\app\cnf\cache\4.2.0\org.openhab.demo.app r/w=false]] null
Status ERROR: bndtools.core code=0 org.openhab.binding.astro;version=[2.5.0,2.5.1) Not found in [bndtools.m2e.MavenImplicitProjectRepository@52314f7f, bnd-cache [C:/Users/Tomek/.bnd/default-ws/cnf/cache/4.2.0/bnd-cache r/w=false], org.openhab.demo.app [C:\openhab\openhab-demo\app\target\tmp\resolve\app\cnf\cache\4.2.0\org.openhab.demo.app r/w=false]] null
Status ERROR: bndtools.core code=0 org.openhab.binding.pcf8574;version=[2.5.0,2.5.1) Not found in [bndtools.m2e.MavenImplicitProjectRepository@52314f7f, bnd-cache [C:/Users/Tomek/.bnd/default-ws/cnf/cache/4.2.0/bnd-cache r/w=false], org.openhab.demo.app [C:\openhab\openhab-demo\app\target\tmp\resolve\app\cnf\cache\4.2.0\org.openhab.demo.app r/w=false]] null
This is harder than I expected
I had similar issues today, closed the IDE and stopped openHAB development
The current situation is a bit madness, I agree.
But there are only about 20 bindings left to port, before we can write a new binding development documentation and find out what’s the best way to do things. I assume the problem will go away if you “resolve bnd” once more from the UI. The problem -> That will “break” other stuff at the moment.
I watch this issue, the table is getting smaller and smaller
I’ll wait until the migration finish.
I wanted to finish by binding before the next milestone release because new bindings/updates require a new version of openHAB.
While reading issues I found Your PR. You are trying to split parts of the core into separate bundles.
I’ve started wondering: maybe add-ons/bindings could be separated from the main bundle?
Currently, when there is a bug in binding and it gets fixed we have two options:
manually install that binding
wait till next release of openHAB
Wouldn’t it be awesome if we could create, version and build each binding separately?
This would allow to quickly deploy fixes and new features.
Currently in Paper UI in bindings You see all bindings that are already there, all You must do is just enable them. Why not list bindings/add-ons/etc that are available to download?
Take a look at nuget, npm and others. Each binding is already built, it has dependencies listed, so it could be easily downloaded.
I know that bindings heavily relay on openHAB version, so each package should have minimum openHAB version requirement. This is how NuGet works - if You have a .NET 3.5 application You won’t see packages that require .NET 4.7.
Node-RED has this type of nodes management mechanism.
I know that this is getting a bit of the topic, but this is somehow related to creating and distributing new bindings.
Hopefully this is the right place to ask my question because I already have my dev environment running without errors.
I’m looking for a way to add external jars in my binding. For example different version of org.apache.commons.net. How and where do I put them and what has to be done so that they resolve properly?
“RTFM” answer suits just fine, but point me to the right manual
Thanks for the valuable links. I’ve read the doc behind second link but for some unknown reason missed the first one. This gets me much further.
Thanks again
I’ve also managed to get a working Eclipse environment for the Verisure binding that is WIP using the demo application and then importing the Verisure binding project in Eclipse.
The binding uses an external lib jsoup-1.11.3.jar that is present in the openhab2-addons/bundles/org.openhab.binding.verisure/lib folder:
jannegpriv in /Users/jannegpriv/git/openhab2-master/git/openhab2-addons/bundles/org.openhab.binding.verisure (4788-verisure) (12 entries, 3 hidden)
$ ll lib/
total 1248
-rw-r--r--@ 1 jannegpriv staff 241622 May 6 22:29 gson-2.8.5.jar
-rw-r--r-- 1 jannegpriv staff 395748 May 4 21:38 jsoup-1.11.3.jar
It compiles fine in Eclipse and when commenting out the import for org.jsoup and all other rows using jsoup the binding starts up without errors and I can debug via the app/Debug OSGi button and launch PaperUI and start to configure my things.
However when trying to use the org.jsoup functionality the framework starts up with the following error:
! Failed to start bundle org.openhab.binding.verisure-2.5.0.201905072051, exception Could not resolve module: org.openhab.binding.verisure [123]
Unresolved requirement: Import-Package: org.jsoup; version="[1.11.0,2.0.0)"
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.verisure [123]
Unresolved requirement: Import-Package: org.jsoup; version="[1.11.0,2.0.0)"
at org.eclipse.osgi.container.Module.start(Module.java:447)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:431)
at aQute.launcher.Launcher.startBundles(Launcher.java:528)
at aQute.launcher.Launcher.activate(Launcher.java:427)
at aQute.launcher.Launcher.run(Launcher.java:306)
at aQute.launcher.Launcher.main(Launcher.java:152)
I would also like to use a newer version of gson (2.8.5) that I also have included, since I get a parsing error for a json when using the OH version compared to a local test using gson-2.8.5.jar.
What am I missing?
At the moment we have not finalized the ide setup for the new buildsystem. The demo app is not using karaf so editing that file will not help to find the library at runtime.
Instead you want to go to the bndrun file editor and click on resolve. It should add the poms.xml defined dependencies to the bndrun file. That’s your runtime environment file at the moment, not the karaf feature file.
Cheers David
No I seem to have ended up in the same error as @Misiu had above:
Status ERROR: bndtools.core code=0 Cannot find /error/org.openhab.binding.verisure;version=0 Not found in [bndtools.m2e.MavenImplicitProjectRepository@3999a433, bnd-cache [/Users/jannegpriv/.bnd/default-ws/cnf/cache/4.2.0/bnd-cache r/w=false], org.openhab.demo.app [/Users/jannegpriv/git/openhab2-master/git/openhab-demo/app/target/tmp/resolve/app/cnf/cache/4.2.0/org.openhab.demo.app r/w=false]] null
Status ERROR: bndtools.core code=0 org.openhab.binding.verisure;version=0 Not found in [bndtools.m2e.MavenImplicitProjectRepository@3999a433, bnd-cache [/Users/jannegpriv/.bnd/default-ws/cnf/cache/4.2.0/bnd-cache r/w=false], org.openhab.demo.app [/Users/jannegpriv/git/openhab2-master/git/openhab-demo/app/target/tmp/resolve/app/cnf/cache/4.2.0/org.openhab.demo.app r/w=false]] null
probably after I pressed the Resolve button.
Maybe I need to set up the environment from scratch again or is there a way to fix this?
It should add the poms.xml defined dependencies to the bndrun file.
Where is the bndrun file located?
After setting up the demo app again I now have a functional IDE environment again.
However I still cannot get the runtime environment to resolve my added dependency library jsoup-1.11.3.jar.
The jar-file is present in the lib folder of my binding: openhab2-addons/bundles/org.openhab.binding.verisure/lib
and the verisure bindings pom.xml looks like this:
When I press the Resolve button the jsoup lib is not listed as an Optional Resource. I have a number of jsoup.jar files downloaded in my .m2 folder:
$ cd jsoup/
jannegpriv in /Users/jannegpriv/.m2/repository/org/jsoup/jsoup (8 entries, 0 hidden)
total 0
drwxr-xr-x 10 jannegpriv staff 320 May 8 22:31 1.10.1
drwxr-xr-x 5 jannegpriv staff 160 Sep 25 2018 1.10.2
drwxr-xr-x 10 jannegpriv staff 320 May 8 22:29 1.10.3
drwxr-xr-x 9 jannegpriv staff 288 Nov 5 2018 1.11.2
drwxr-xr-x 10 jannegpriv staff 320 May 4 23:50 1.11.3
drwxr-xr-x 7 jannegpriv staff 224 Sep 25 2018 1.7.1
drwxr-xr-x 7 jannegpriv staff 224 Aug 30 2018 1.7.2
drwxr-xr-x 10 jannegpriv staff 320 May 8 22:29 1.8.3
Error when pressing Run OSGi
:16:56.158 [main] WARN o.o.p.w.u.ServletContainerInitializerScanner:136 - failed to parse and instantiate of javax.servlet.ServletContainerInitializer in classpath
! Failed to start bundle org.openhab.binding.verisure-2.5.0.201905132101, exception Could not resolve module: org.openhab.binding.verisure [121]
Unresolved requirement: Import-Package: org.jsoup; version="[1.11.0,2.0.0)"
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.verisure [121]
Unresolved requirement: Import-Package: org.jsoup; version="[1.11.0,2.0.0)"
at org.eclipse.osgi.container.Module.start(Module.java:447)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:431)
at aQute.launcher.Launcher.startBundles(Launcher.java:528)
at aQute.launcher.Launcher.activate(Launcher.java:427)
at aQute.launcher.Launcher.run(Launcher.java:306)
at aQute.launcher.Launcher.main(Launcher.java:152)
Any tips of what might be wrong or missing are appreciated!
The buildsystem section of the doc might help. Just add the dependency to the lib directory of your binding for the time being.
Usually you would list it as runtime dependency in your features.xml file. But for development that doesn’t really work.
I tried to follow the instructions in the buildsystem documentation and I’ve added the dependency to the jsoup jar in the bindings pom.xml as shown above but what exactly does this mean:
Just add the dependency to the lib directory of your binding for the time being.
How do I accomplish that?
Sorry for the maybe newbie questions but I’m really eager to get this working so that I can continue with the binding implementation
Hello,
I add the library in this window.
On your binding folder, right button and select properties
I have the jsoup library in the lib foider of my binding and my Java Build Path has the library listed:
image.png2035×1267 923 KB
jannegpriv in /Users/jannegpriv/git/openhab2-master/git/openhab2-addons/bundles/org.openhab.binding.verisure (4788-verisure) (11 entries, 3 hidden)
total 72
-rw-r--r-- 1 jannegpriv staff 495 May 4 21:38 NOTICE
-rw-r--r-- 1 jannegpriv staff 23857 May 4 21:38 README.md
drwxr-xr-x 5 jannegpriv staff 160 May 4 20:58 bin
drwxr-xr-x 4 jannegpriv staff 128 May 6 22:29 lib
-rw-r--r-- 1 jannegpriv staff 797 May 13 23:00 pom.xml
-rw-r--r-- 1 jannegpriv staff 973 May 7 23:51 pom.xml.bak
drwxr-xr-x 4 jannegpriv staff 128 May 5 00:31 src
drwxr-xr-x 13 jannegpriv staff 416 May 8 23:12 target
jannegpriv in /Users/jannegpriv/git/openhab2-master/git/openhab2-addons/bundles/org.openhab.binding.verisure (4788-verisure) (11 entries, 3 hidden)
$ ls -l lib/
total 1248
-rw-r--r--@ 1 jannegpriv staff 241622 May 6 22:29 gson-2.8.5.jar
-rw-r--r-- 1 jannegpriv staff 395748 May 4 21:38 jsoup-1.11.3.jar
gson-2.8.5.jar is also present in the lib folder but it is also part of the demo.app so I guess that is why I don’t get any problems with resolving gson library at runtime.
image.png1386×842 169 KB
So it is not a problem at compile time, only at runtime when either using the Run or Debug OSGi buttons.
If I comment out my imports of org.jsoup.* I can start and debug my binding without any problem.
However since I’ve used jsoup to parse HTML files before moving to the new bnd environment, I would really like the possibility to use jsoup in my further binding development. I could maybe use String/StringBuilder to accompish the same logic, however the code will be so much more hard to understand.
Can I manually add it to the openhab-demo/app/app.bndrun file?
In that case under which part? runbundles or runrequires?
Another thing I’ve noticed is that jsoup is used by 2 official bindings:
However none of those binding have the jsoup library in respective bindings lib folder. They also refer to 2 different versions of jsoup library. How can those bindings resolve jsoup at runtime?
Via the features.xml file. We do not encourage people to put libs into the lib dir. I suggested that only for you to keep going with your setup.
In short:
For openhab use the features.xml for
For local development use the libs dir or edit the bndrun file. The latter is preferred but requires a bit more knowledge.