2016-07-26 6 views
0

나는 camel-archetype-blueprint maven 아키타 입을 사용하여 OSGi 번들을 만들었습니다. 나는 Karaf에 이것을 설치하려고 시도했으나 번들은 GracePeriod로 들어갔다. diag를 실행 한 후에는 jar 파일 내부에 종속성이 없습니다.Karaf : 내 항아리에 누락 된 클래스

좋아, 긴 버전 :

$ jar tvf myproject-1.0-SNAPSHOT.jar 
    455 Tue Jul 26 11:25:10 UTC 2016 META-INF/MANIFEST.MF 
    0 Tue Jul 26 11:25:10 UTC 2016 META-INF/ 
    0 Tue Jul 26 11:25:10 UTC 2016 META-INF/maven/ 
    0 Tue Jul 26 11:25:10 UTC 2016 META-INF/maven/com.petewall/ 
    0 Tue Jul 26 11:25:10 UTC 2016 META-INF/maven/com.petewall/myproject/ 
    143 Tue Jul 26 11:25:10 UTC 2016 META-INF/maven/com.petewall/myproject/pom.properties 
    3418 Tue Jul 26 11:25:06 UTC 2016 META-INF/maven/com.petewall/myproject/pom.xml 
    0 Tue Jul 26 11:25:10 UTC 2016 OSGI-INF/ 
    0 Tue Jul 26 11:25:10 UTC 2016 OSGI-INF/blueprint/ 
    1376 Tue Jul 26 11:20:12 UTC 2016 OSGI-INF/blueprint/blueprint-bean.xml 
    961 Tue Jul 26 11:20:12 UTC 2016 OSGI-INF/blueprint/blueprint-service.xml 
    0 Tue Jul 26 11:25:10 UTC 2016 com/ 
    0 Tue Jul 26 11:25:10 UTC 2016 com/petewall/ 
    143 Tue Jul 26 11:24:56 UTC 2016 com/petewall/Hello.class 
    1022 Tue Jul 26 11:24:56 UTC 2016 com/petewall/HelloBean.class 
    676 Tue Jul 26 11:20:12 UTC 2016 log4j.properties 

내가 deploy 디렉토리에이 jar 파일을 떨어 :

는 원형에서 생성 된 jar 파일이 원형에서 포함 된 안녕하세요 HelloBean 클래스가 포함

내 karaf 인스턴스. 번들이 설치되고 bundle:list 명령에 나열됩니다. 그러나 번들이 시작되면 GracePeriod로 이동합니다. 그것은 종속성 실종 보여줍니다 진단 :

[email protected]()> exports 
Package Name      | Version  | ID | Bundle Name 
----------------------------------------------------------------------------- 
... 
com.petewall      | 1.0.0.SNAPSHOT | 98 | myproject 
... 

그리고 classes 명령 : 난

[email protected]()> classes 
... 
com/petewall/Hello.class 
com/petewall/HelloBean.class 

그러나

[email protected]()> bundle:diag 98 
Camel Blueprint Route (98) 
-------------------------- 
Status: GracePeriod 
Blueprint 
7/26/16 6:26 PM 
Missing dependencies: 
(objectClass=com.petewall.Hello) 

을, 그 클래스는 심지어 karaf의 exports 명령을 사용하여 발견 이러한 모든 기술 (Karaf, Camel, OSGi 등)에 새로운 것이므로 뭔가를 놓치고 있다고 확신합니다. 제발, 누군가가 나를 올바른 방향으로 향하게 할 수 있습니까?

업데이트 1 : archetype은 청사진 서비스와 빈을 정의하는 것으로 보이는 두 개의 XML 파일을 생성합니다.

청사진-bean.xml :

<?xml version="1.0" encoding="UTF-8"?> 
<blueprint xmlns="..." xmlns:xsi="..." xmlns:cm="..." xsi:schemaLocation="..."> 
    <cm:property-placeholder persistent-id="HelloBean" update-strategy="reload"> 
    <cm:default-properties> 
     <cm:property name="greeting" value="Hi from Camel" /> 
    </cm:default-properties> 
    </cm:property-placeholder> 

    <bean id="helloBean" class="com.petewall.HelloBean"> 
    <property name="say" value="${greeting}"/> 
    </bean> 

    <camelContext id="blueprint-bean-context" xmlns="http://camel.apache.org/schema/blueprint"> 
    <route id="timerToLog"> 
     <from uri="timer:foo?period=5000"/> 
     <setBody> 
     <method ref="helloBean" method="hello"/> 
     </setBody> 
     <log message="The message contains ${body}"/> 
     <to uri="mock:result"/> 
    </route> 
    </camelContext> 
</blueprint> 

청사진-service.xml :

<?xml version="1.0" encoding="UTF-8"?> 
<blueprint xmlns="..." xmlns:xsi="..." xmlns:cm="..." xsi:schemaLocation="..."> 
    <reference id="helloService" interface="com.petewall.Hello" /> 
    <camelContext id="blueprint-service-context" xmlns="http://camel.apache.org/schema/blueprint"> 
    <route id="timerToLog"> 
     <from uri="timer:foo?period=5000"/> 
     <setBody> 
     <method ref="helloService" method="hello"/> 
     </setBody> 
     <log message="The message contains ${body}"/> 
     <to uri="mock:result"/> 
    </route> 
    </camelContext> 
</blueprint> 

는 아키가 인터페이스를 생성 Hello 번 방법 정의를 String hello(). HelloBean 클래스는 해당 인터페이스를 구현하고 private String say 매개 변수를 사용하여 hello() 메서드가 인쇄하는 내용을 변경합니다.

답변

2

"누락 된 종속성"으로보고 한 청사진 보고서는 실제로 누락 된 OSGi 서비스입니다.

청사진 XML을 게시하지 않았기 때문에 확신하기가 어렵지만 오류 메시지가이를 강력하게 제시합니다. <reference> 요소가 com.petewall.Hello 서비스를 참조하는 것일 수 있습니다.

번들은 com.petewall.Hello 인스턴스를 서비스로 제공합니까? 이 이름을 가진 번들에 클래스 파일이 존재한다는 사실은 부적절합니다. 아마도 당신은이 방법을 잘못 사용하고 번들이 서비스를 제공하고있을 것입니다. 높은 수준에서 당신이하려고하는 것에 대해 좀 더 설명 할 수 있습니까?

+0

기본적으로 Karaf가로드 한 번들을 원하고 낙타 타이머를 활성화하여 주기적으로 기능을 호출합니다. – Pete

+0

그래서'Hello' 인터페이스의 역할은 무엇입니까? 이것은 주기적으로 호출되어야하는 기능을 정의합니까? Camel에 익숙하지 않지만 Camel이 정의한 인터페이스를 사용하여 타이머 기능을 구현해야합니까? –

+0

청사진 정의에서 제공하는 OSGi 서비스는 동일한 번들에 정의 된 종속성에 연결되지 않으므로 해당 묶음을 내부적으로 빈으로 참조해야합니다. –

1

archetype은 bean에 메소드를 호출하는 두 가지 스타일을 작성한 것 같습니다.

첫 번째 청사진은 HelloBean을 로컬로 정의하고 이에 대한 메소드를 호출합니다. 이것은 독자적으로 실행할 수 있습니다. OSGi 서비스는 공개하지 않습니다.

두 번째 청사진은 OSGi 서비스를 참조하고 이에 대한 메소드를 호출합니다. 해당 인터페이스가있는 서비스를 내보내는 번들을 설치하지 않으면이 작업을 시작할 수 없습니다.

번들의 모든 청사진 xml이 하나의 청사진 컨텍스트로 병합됩니다. 따라서 병합 된 청사진 컨텍스트는 런타임에 HelloBean 서비스가 존재할 때만 시작됩니다.

두 번째 blueprint.xml을 생략하면 번들이 잘 시작됩니다.