Getting started with OH Dev

this quick fix solves it permanently (for this project). I should be at least added to the setup instructions, this gives guidance to the new developer. Fixing the setup procedure itself would be the “clean solution”.

Another question:
I making good progress on a new binding for the Rachio sprinkler controllers

Now I would like to create a first beta jar, so

  • Eclipse->select the project->right click->export->Java/jar file
    21
  • then selecting the resources and output folder
    06
  • generaring the jar results in a warning (see last line)

When I copy the generated jar to the addons folder on my Pi nothing happens. Nothing is displayed on the console / in the log. The binding is not show with bundle:list.

So, how to export the jar correctly?

using “mvn install” in the binding directory I was able to build a jar after fixing build.properties. The scripts, which generates the skeleton creates the following file:

source..=src/main/java/
output..=target/classes
bin.includes=META-INF/,\
             .,\
             OSGI-INF/,\
             ESH-INF/,\
             NOTICE

However, there is no file NOTICE. Instead you need to include about.html:

source..=src/main/java/
output..=target/classes
bin.includes=META-INF/,\
             .,\
             OSGI-INF/,\
             ESH-INF/,\
             about.html

Now the bundle is show under bundle:list with status Installed, but it doesn’t start.
It’n not able to resolve the dependency on com.google.json.jar even it’s included int MANIFEST.MF

Import-Package: com.google.gson;version="2.7.0",org.apache.commons.net
 ;version="3.2.0",org.eclipse.jdt.annotation;resolution:=optional,org.
 eclipse.smarthome.config.core,org.eclipse.smarthome.config.discovery,
 org.eclipse.smarthome.core.library.types,org.eclipse.smarthome.core.t
 hing,org.eclipse.smarthome.core.thing.binding,org.eclipse.smarthome.c
 ore.thing.binding.builder,org.eclipse.smarthome.core.thing.type,org.e
 clipse.smarthome.core.types,org.openhab.binding.rachio,org.openhab.bi
 nding.rachio.handler,org.slf4j

How could I include the used libs in my jar?

I had to modify my MANIFEST.MF is several ways (the generated one doesn’t conform to the code analysis) and also include gson-2.7.jar manually - hmm, strange.

Manifest-Version: 1.0
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: 
 .,
 lib/gson-2.7.jar
Bundle-ManifestVersion: 2
Bundle-Name: Rachio Binding
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: org.openhab.binding.rachio;singleton:=true
Bundle-Vendor: openHAB
Bundle-Version: 2.3.0.qualifier
Export-Package: 
 org.openhab.binding.rachio,
 org.openhab.binding.rachio.handler
Import-Package: 
 com.google.gson,
 org.apache.commons.net;version="3.2.0",
 org.eclipse.jdt.annotation;resolution:=optional,
 org.eclipse.smarthome.config.core,
 org.eclipse.smarthome.config.discovery,
 org.eclipse.smarthome.core.library.types,
 org.eclipse.smarthome.core.thing,
 org.eclipse.smarthome.core.thing.binding,
 org.eclipse.smarthome.core.thing.binding.builder,
 org.eclipse.smarthome.core.thing.type,
 org.eclipse.smarthome.core.types,
 javax.servlet,
 javax.servlet.http,
 org.osgi.framework,
 org.osgi.service.component.annotations;resolution:=optional,
 org.osgi.service.http,
 org.openhab.binding.rachio,
 org.openhab.binding.rachio.handler,
 org.slf4j
Service-Component: OSGI-INF/*.xml

It works, but really not sure if that is the recommended way.

You may could help me with another topic
I need the readf a parm from the services config (rachio.cfg), but couldn’t find a function to do that. I’m able to read sthg. from the things definition, but not from a cfg. Reading this as a plain file sounds strange.

if you have problems that OH doesn’t build anymore, because imports to javax.measure are not found, check this out: Can’t build current code base (repository)

That’s a step by step how to complete/fix the default installation after a fresh install.

Hi Markus,

In case you’re still into this: you should add your library dependencies to the manifest file, either by editing it as plain text or using the visual/form-based editor on Eclipse. If you have a dependency on your code that is not added there, Eclipse can also suggest adding it as an imported package via the Quick Fix options. Either way, you need to have it added to MANIFEST.MF so ll dependencies are properly resolved during the build process.

To load configuration from a file you don’t need to use any functions, you can rely on the OSGi configuration management: you should set the configuration-pid to “binding.rachio”, either by adding the configuration-pid=“binding.rachio” attribute on your ThingHandlerFactory component config under OSGI-INF, or with a @Component annotation on the class source code, which will generate the respective attribute on the XML. With that, you can place a file named binding.rachio.cfg in the openHAB/etc/services directory. With this, the framework will provide any properties defined in this file as a Map<String, Object> parameter passed to the activate() method of your ThingHandlerFactory implementation.

Please let me know if you need any additional info.

1 Like

Hi Flavio,

the first part was related to a missing software site (OH 3rd party bundles) when building the core and other stuff. The link describes how to fix it.

thanks for your info - I checked implementing an activate method, but it doesn’t receives the .cfg parameters

services/rachio.cfg:

apiKey=12345

HandlerFactory.java

@Component(service = { ThingHandlerFactory.class,
        RachioHandlerFactory.class }, immediate = true, configurationPid = "binding.rachio")
public class RachioHandlerFactory extends BaseThingHandlerFactory {
   /**
     * OSGi activation callback.
     *
     * @param config Service config.
     */
    @Activate
    protected void activate(Map<String, Object> config) {
        logger.debug("RachioBridge: Activate");
        for (HashMap.Entry<String, Object> ce : config.entrySet()) {
            logger.debug("  {}: {}", ce.getKey(), ce.getValue());
            Object e = ce.getValue();
        }
    }

debug output:

osgi> 2018-03-17 18:11:25.553 [DEBUG] [o.o.b.r.i.RachioHandlerFactory:66   ] - RachioBridge: Activate
2018-03-17 18:11:27.072 [DEBUG] [o.o.b.r.i.RachioHandlerFactory:68   ] -   component.name: org.openhab.binding.rachio.internal.RachioHandlerFactory
2018-03-17 18:11:32.957 [DEBUG] [o.o.b.r.i.RachioHandlerFactory:68   ] -   component.id: 99

Maybe you can help with another error while running “mvn install” I get a build error

[ERROR] .binding.rachio/META-INF/MANIFEST.MF:[0]
The package  should be marked as "internal" if it is not exported.
[ERROR] .binding.rachio/META-INF/MANIFEST.MF:[0]
The package org should be marked as "internal" if it is not exported.
[ERROR] .binding.rachio/META-INF/MANIFEST.MF:[0]
The package org.openhab should be marked as "internal" if it is not exported.
[ERROR] .binding.rachio/META-INF/MANIFEST.MF:[0]
...
[ERROR] Failed to execute goal org.openhab.tools.sat:sat-plugin:0.4.1:report (default) on project org.openhab.binding.rachio: 
[ERROR] Code Analysis Tool has found 4 error(s)! 
[ERROR] Please fix the errors and rerun the build. 

However, the MANIFEST.MF looks good for me:

Manifest-Version: 1.0
Bundle-ActivationPolicy: lazy
Bundle-ManifestVersion: 2
Bundle-Name: Rachio Binding
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: org.openhab.binding.rachio;singleton:=true
Bundle-Vendor: openHAB
Bundle-Version: 2.3.0.qualifier
Bundle-ClassPath: 
 .,
 lib/gson-2.7.jar
Import-Package: 
 com.google.gson,
 javax.servlet,
 javax.servlet.http,
 org.apache.commons.net,
 org.apache.commons.net.util;version="3.2.0",
 org.eclipse.jdt.annotation;resolution:=optional,
 org.eclipse.smarthome.config.core,
 org.eclipse.smarthome.config.core.status,
 org.eclipse.smarthome.config.discovery,
 org.eclipse.smarthome.core.library.types,
 org.eclipse.smarthome.core.thing,
 org.eclipse.smarthome.core.thing.binding,
 org.eclipse.smarthome.core.thing.binding.builder,
 org.eclipse.smarthome.core.thing.type,
 org.eclipse.smarthome.core.types,
 org.openhab.binding.rachio,
 org.openhab.binding.rachio.handler,
 org.osgi.framework,
 org.osgi.service.cm,
 org.osgi.service.component.annotations;resolution:=optional,
 org.osgi.service.http,
 org.slf4j
Export-Package: 
 org.openhab.binding.rachio,
 org.openhab.binding.rachio.handler
Service-Component: OSGI-INF/*.xml

The is no package org and org.openhab. I found a thread discussing some problems related to XML checking by the code analysis tool, but nothing related to MANIFEST.MF

First check if on your /OSGI-INF/org.openhab.binding.rachio.HandlerFactory.xml the configuration-pid attribute of the element scr:component is indeed set to binding.rachio (it should have been generated there by your annotations).

Then please notice that the configuration file should be named binding.rachio.cfg, not rachio.cfg.

For the Maven errors you are getting, it is really strange, I have never seen exactly that - it is complaining about some seemingly dummy packages you have, even a package with an empty name:

The package  should be marked as "internal" if it is not exported.

The usual way to fix this problem for an actual package that exists on your project but is not exported is by listing it on Export-Package, but marked with x-internal. To see if the third error you get goes away, you can try adding that:

Export-Package: [...],
 org.openhab; x-internal:=true

I think it’s not a proper fix, but maybe it gives you more visibility on the root cause of this issue. Perhaps you have those packages somehow appearing on src/main/java so you need to remove some empty directory from there or something like this?

Hi,

I am also new to OpenHab development and had my starting problems :wink: The learning curve is very flat especially due to the lacking documentation of the internal stuff. I always had the feeling that I didn’t know exactly what I was doing right now. Since everything is based on Osgi, I’ve read through a few tutorials about this topic. Especially this one helped me a lot to understand what is happening under the hood of OpenHab, because imho the most stuff inside OpenHab and ESH is based on Declarative Services:
http://blog.vogella.com/2016/06/21/getting-started-with-osgi-declarative-services/

EDIT: And of course this page: https://docs.openhab.org/developers/prerequisites/osgi.html

Maybe it’s helpful for you too :slight_smile:
Best regards, Andi

1 Like

Hi Andi,
thanks for your contribution. I added the links to my own Mini-Tutorial recording my findings and steps - just to be able to repeat it, when Dev env crashed etc.

I would love to share experiences here and help others to speed up their initial phase.
Cheers, Markus

@Kai Today I tried to switch my dev environment to 2.5. I want to have a fresh install so I downloaded the Eclipse installer, performed the update in advanced mode, selected Java Devlopers, but obviously there is no openHAB project anymore to select.

Could it be that the build master is inconsitent or the Eclipse foundaten forgot/remoev the OH project? Any other idea?

PS: I downloaded the installer, which is liked into the page describing the IDE setup

ok, fount it; it’s under GitHub projects :crazy_face:

After installing a fresh Eclipse and doing the initial build I get the following problems when starting the debug session:
02
with no additional information.

I’m also not able to start PaperUI
44
whereas the Basic UI is working.

any idea?

I tried once more a fresh install of the addon dev pofile and another one with the core dev profile. Some results. Did someone else tried a fresh install of the dev environment?

I, too, have been trying to get the IDE up and running. You’ve gotten further than I have, although you’ve been working at it longer.

In the first post, you mentioned videos from @Kai - where are those? I haven’t found them. All I’ve found is steps to set up the IDE and general information about the OSGI model used to structure the bundles, etc.

I see people saying, “Step up and do things!” and then it’s one huge step before you can actually get anything going.

Also, to answer your question: When I start through the IDE I can get to Basic UI, but Paper UI fails. There’s a bunch of errors, which I suspect shouldn’t be there. I wonder if this is fallout from the ESH removal or if something’s just broken.