OSGI Неразрешенное требование: Import-Package: com.pi4j.io.gpio

Я хочу написать комплект OSGI (Eclipse SmartHome Binding) для GPIO Raspberry Pi.
Для GPIO мне нужно включить библиотеки Pi4J. Я добавил их в папку lib в папке моего проекта и добавил pi4j-core.jar в свой путь сборки.

Это мой код:

/**
 * 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();
            }
    }   

}

У класса нет проблем с поиском импорта Pi4J и экспорта в банку, также нет проблем. Только если я запускаю его непосредственно в Eclipse OpenHab_runtime, я получаю ошибку:

!Проверка: были обнаружены следующие проблемы: org.openhab.binding.statusgpio Отсутствует ограничение: пакет импорта: com.pi4j.io.gpio; версия="0.0.0"

Когда я запускаю OSGI Bundle на своем Raspberry Pi (и на своем Win-компьютере), я получаю сообщение:

начать 92

gogo: BundleException: Не удалось разрешить модуль: org.openhab.binding.statusgpio [92]
Неразрешенное требование: Import-Package: com.pi4j.io.gpio

Я думаю, что мне нужно сделать что-то еще с Bundle, чтобы OSGI нашла библиотеки Pi4J???

Спасибо за помощь.


person Arjuna    schedule 24.04.2015    source источник


Ответы (1)


Я обнаружил собственную ошибку:
я думал, что мне не нужно добавлять "com.pi4j.io.gpio" во включения в файле манифеста, но я не хочу импортировать его из других пакетов OSGI, я хочу импортировать это из уже импортированного JAR. Поэтому мне просто пришлось удалить эту строку, и все заработало.
Изменить:
Я нашел ответ здесь: https://github.com/ECF/RaspberryPI/tree/master/bundles/com.pi4j
Это мой 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
person Arjuna    schedule 27.04.2015