我使用camel-archetype-blueprint maven原型创建了一个OSGi包。然后我试图把它安装到卡拉夫,但是捆绑正在进入GracePeriod。运行诊断之后,它缺少jar文件本身内的依赖项。Karaf:从我自己的jar中缺少类
好,长版本:
从原型生成的jar文件包含了从原型包括您好,为helloBean类:
$ 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
我放弃了这个jar文件到deploy目录我的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
命令竟然发现所有这些技术都非常新颖(卡拉夫,骆驼,OSGi等),所以我相信我错过了一些东西。请有人指点我在这里的正确方向吗?
UPDATE 1: 原型生成两个XML文件,它们似乎定义了蓝图服务和bean。
蓝图-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()
方法打印的内容。
基本上,我想要一个包,由Karaf加载,并在骆驼定时器上激活以定期调用函数。 – Pete
那么'Hello'接口的作用是什么?这是否定义了应该定期调用的函数?我不熟悉Camel,但是你不需要使用Camel定义的接口来实现定时器功能吗? –
请注意,blueprint定义提供的OSGi服务不会连接到同一个bundle中定义的依赖项,因为这确保您在内部将它们引用为bean。 –