OSGi 번들이 Felix 호스트 응용 프로그램으로 시작되지 않음 (OSGi Bundle not starting with Felix Host application)


문제 설명

OSGi 번들이 Felix 호스트 응용 프로그램으로 시작되지 않음 (OSGi Bundle not starting with Felix Host application)

런타임에 확장을 로드하는 기능을 제공하기 위해 호스트 애플리케이션에서 Apache Felix를 사용하고 있습니다. 메커니즘은 훌륭하게 작동하지만 특정 종속성을 포함하면 시작되는 번들과 관련하여 매우 변덕스러운 동작이 있습니다. 예를 들어 내 pom.xml에서 다음을 사용하는 경우:

<packaging>bundle</packaging>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven‑bundle‑plugin</artifactId>
            <version>2.5.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle‑SymbolicName>${project.groupId}.${project.artifactId}</Bundle‑SymbolicName>
                    <Bundle‑Name>${project.artifactId}</Bundle‑Name>
                    <Bundle‑Version>1.0.0</Bundle‑Version>
                    <Bundle‑Activator>${pom.groupId}.activator.Activator</Bundle‑Activator>
                    <Include‑Resource>{maven‑resources}, {maven‑dependencies}</Include‑Resource>
                    <Import‑Package>*</Import‑Package>
                    <Embed‑Dependency>jackson‑core</Embed‑Dependency>
                    <Embed‑Transitive>true</Embed‑Transitive>
                </instructions>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven‑compiler‑plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.apache.felix</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>1.4.0</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjtools</artifactId>
        <version>1.8.2</version>
    </dependency>
    <dependency>
        <groupId>co.ff36</groupId>
        <artifactId>halo.core</artifactId>
        <version>1.0.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

모든 것이 완벽하게 작동하고 번들이 등록되고 시작됩니다. 그러나 번들에 async‑http‑client를 포함하면 등록되지만 시작되지 않습니다! 부모가 부모 호스트 응용 프로그램에서 종속성을 노출하더라도 번들에 종속성을 포함하려고 시도했습니다. 컴파일된 번들 내부를 살펴보면 jar가 포함되었지만 여전히 실제로 시작되지 않습니다.

추가 시도:

    <dependency>
        <groupId>com.ning</groupId>
        <artifactId>async‑http‑client</artifactId>
        <version>1.9.31</version>
    </dependency>

수정:

<Embed‑Dependency>jackson‑core, async‑http‑client</Embed‑Dependency>

이러한 옵션 중 어느 것도 작동하지 않습니다. 호스트 응용 프로그램에서 오류가 발생하지 않으며 일부 라이브러리에서는 이러한 오류가 발생하지만 다른 라이브러리에서는 발생하지 않는 이유를 알 수 없습니다.


참조 솔루션

방법 1:

The Jackson can be accessed as OSGi bundles you don't need to embed it. If you have felix webconsole or other type of console you can check what import (or capability) is not presented which causes that the bundle cannot came to ACTIVE state. As the POM shows all dependecies included in transitive form. It's not a good idea to use that, because it means no classes loaded from other bundles, instead of everything is embeded, which means you create a monolithic bundle which is not using anything from bundles.

Another possible reason to not start is that the activator calls some method which throws an exception which will invalidate your activator, as the OSGi spec defines. Recommended to check your log, maybe there is some reflection instantiate classes in the code which cannot be resolved, because its not manifested by bundle plugin ‑ only that packages can be imported which are presented in classes import's.

방법 2:

After further investigation it turns out that the problem is related to versioning. The bundle MANIFEST.MF that is created explicitly states the versions for some import packages:

Import‑Package: ...,com.fasterxml.jackson.core.type;version="[2.4,3)",com.ning.http.client;version="[1.9,2)",
 org.osgi.framework;version="[1.5,2)"

However, the host application does not specify a version:

Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA ‑> ... com.ning.http.client ...

It appears that the version must be explicitly stated in the host and it must match the bundles import otherwise the bundle won't activate.

(by tarkaCsákány Róberttarka)

참조 문서

  1. OSGi Bundle not starting with Felix Host application (CC BY‑SA 2.5/3.0/4.0)

#apache-felix #maven #bnd #java






관련 질문

Apache Felix 웹 콘솔 브랜딩 (Branding Apache Felix web console)

포함된 Apache Felix를 시작할 수 없습니다. (Cannot start embeded Apache Felix)

Glassfish OSGI 웹 콘솔 자격 증명 (Glassfish OSGI Webconsole Credentials)

Android에 OSGi Felix 포함 (Embed OSGi Felix in Android)

Amdatu OSGI 이벤트 처리기 다른 수신기가 수신 대기 중일 때 수신 대기 시간 지연 (Amdatu OSGI Event Handler time delay to listen when other listener are listening)

OSGi 번들이 Felix 호스트 응용 프로그램으로 시작되지 않음 (OSGi Bundle not starting with Felix Host application)

임베디드 osgi 프레임워크, 서비스 기능을 호출하는 방법은 무엇입니까? (Embedded osgi framework, how to call service functions?)

kaldi 설치 시 libmkl_tbb_thread.so sth 관련 문제 (A problem related to libmkl_tbb_thread.so sth when installing kaldi)

OSGI(Apache Felix)에서 다른 사람의 번들에 대해 AOP를 구현하는 방법은 무엇입니까? (How to implement AOP for someone else's bundles in OSGI (Apache Felix)?)

OSGi r4.1의 ServiceTracker (ServiceTracker in OSGi r4.1)

번들 OSGI를 업데이트하는 동안 서비스/구성 요소를 계속 실행하는 방법 (How to keep service/componnet running while update bundle OSGI)

Equinox에서 Arquillian 실행 (Running Arquillian in Equinox)







코멘트