OSGI未解决的要求:导入包:com.pi4j.io.gpio [英] OSGI Unresolved requirement: Import-Package: com.pi4j.io.gpio

查看:65
本文介绍了OSGI未解决的要求:导入包:com.pi4j.io.gpio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Raspberry Pi的GPIO编写 OSGI Bundle (Eclipse SmartHome绑定).
对于GPIO,我需要包括Pi4J库.我将它们添加到项目文件夹中的lib文件夹中,并将pi4j-core.jar添加到我的构建路径中.

I want to write an OSGI Bundle (Eclipse SmartHome Binding) for the GPIO's of a Raspberry Pi.
For the GPIO's i need to include the Pi4J libraries. I added them into a lib folder in my project folder and added the pi4j-core.jar to my Build Path.

这是我的代码:

/**
 * Copyright (c) 2014 openHAB UG (haftungsbeschraenkt) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.statusgpio.handler;

import static org.openhab.binding.statusgpio.StatusGPIOBindingConstants.*;

import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.types.Command;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;

/**
 * The {@link StatusGPIOHandler} is responsible for handling commands, which are
 * sent to one of the channels.
 * 
 * @author Arjuna W. - Initial contribution
 */
public class StatusGPIOHandler extends BaseThingHandler {

    ScheduledFuture<?> refreshJob;

    public StatusGPIOHandler(Thing thing) {
        super(thing);
    }

    @Override
    public void initialize() {
        // TODO Auto-generated method stub
        super.initialize();

        startAutomaticRefresh();
    }

    @Override
    public void handleCommand(ChannelUID channelUID, Command command) {
        // TODO Auto-generated method stub

        // do nothing ;)
    }

    private void startAutomaticRefresh() {

        final GpioController gpio = GpioFactory.getInstance();

        // provision gpio pin #02 as an input pin with its internal pull down
        // resistor enabled
        final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(
                RaspiPin.GPIO_02, PinPullResistance.PULL_DOWN);

        // create and register gpio pin listener
        myButton.addListener(new GpioPinListenerDigital() {
            @Override
            public void handleGpioPinDigitalStateChangeEvent(
                    GpioPinDigitalStateChangeEvent event) {
                // display pin state on console
                updateState(new ChannelUID(getThing().getUID(), CHANNEL_LOADING_STATE), new StringType(event.getState().toString()));

            }

        });

            try {
                for (;;) {
                Thread.sleep(1000);
                }

            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }   

}

Class没问题,找到Pi4J导入和导出到jar也是没有问题的.仅当我直接在Eclipse OpenHab_runtime中运行它时,我才会发现错误:

The Class has no problem to find the Pi4J imports and export to a jar is also no problem. Only if I run it directly in the Eclipse OpenHab_runtime I geht the Error:

验证:检测到以下问题:org.openhab.binding.statusgpio缺少约束:导入包:com.pi4j.io.gpio;版本="0.0.0"

当我在Raspberry Pi(和Win PC)上启动OSGI Bundle时,会收到消息:

When I start the OSGI Bundle on my Raspberry Pi (and on my Win PC) I get the message:

开始92

gogo:BundleException:无法解析模块:org.openhab.binding.statusgpio [92]
未解决的要求:导入包:com.pi4j.io.gpio

gogo: BundleException: Could not resolve module: org.openhab.binding.statusgpio [92]
Unresolved requirement: Import-Package: com.pi4j.io.gpio

我想我必须对Bundle做更多的工作,以使OSGI能够找到Pi4J Lib.

I think I have to do something more with the Bundle to let OSGI find the Pi4J Libs???

感谢帮助.

推荐答案

我发现了自己的错误:
我以为我希望将"com.pi4j.io.gpio"添加到清单文件中的include中,但是我不想从其他OSGI捆绑软件中导入它,而是想从一个完全导入的JAR文件中导入.所以我只需要删除这一行,一切都可以正常工作.

我在这里找到了答案: https://github.com/ECF/RaspberryPI/tree/master/bundles/com.pi4j
这是我的manifest.mf:

I found my own mistake:
I thought I hat to add "com.pi4j.io.gpio" to the includes in the Manifest file, but I don't want to import it from other OSGI Bundles, I want to import it from an alteady imported JAR. So I just had to delete this line and everything worked.

I found the answer here: https://github.com/ECF/RaspberryPI/tree/master/bundles/com.pi4j
This is my manifest.mf:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: OutputGPIO Binding
Bundle-SymbolicName: org.openhab.binding.outputgpio;singleton:=true
Bundle-Vendor: openHAB
Bundle-Version: 2.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ClassPath: lib/pi4j-core.jar,
 lib/pi4j-device.jar,
 lib/pi4j-gpio-extension.jar,
 lib/pi4j-service.jar,
 .
Import-Package: com.google.common.collect,
 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.types,
 org.slf4j
Service-Component: OSGI-INF/*
Export-Package: org.openhab.binding.outputgpio,
 org.openhab.binding.outputgpio.handler

这篇关于OSGI未解决的要求:导入包:com.pi4j.io.gpio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆