Spring 基于 apache karaf 的包不起作用
Spring based bundle on apache karaf doesn't work
我正在使用以下命令使用 Maven 创建一个基于 spring 的包
mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes -DarchetypeArtifactId=camel-archetype-spring -DarchetypeVersion=2.15.3 -DgroupId=osgiSpring -DartifactId=osgiSpring -Dversion=1.0-SNAPSHOT -Dpackage=osgiSpring
然后我将这个 Maven 项目导入到 Eclipse 中,只需将 'camel-context.xml' 更改为
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2005-2014 Red Hat, Inc.
Red Hat licenses this file to you under the Apache License, version
2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:C:\input"/>
<to uri="file:C:\output"/>
</route>
</camelContext>
</beans>
之后,我使用 'mvn package' 构建了它,然后将生成的 jar 复制到 Apache Karafs 的部署文件夹中,但 karaf 似乎无法识别该包。
当我 运行 它与 'mvn:camel run' 时,它工作得很好。
它也适用于非 spring 基础捆绑包和激活器。
你的问题是 camel-archetype-spring 只用 camel-maven-plugin 生成 pom.xml 正如你注意到的那样允许你通过 运行 你的代码 'mvn camel:run'.但是,它不会生成正确的 OSGi 清单,因此 Karaf 不会将其识别为 OSGi 包。
解决方案:像这样添加maven-bundle-plugin:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
</plugin>
并像这样设置打包方式:
<packaging>bundle</packaging>
您可以阅读有关 maven-bundle-plugin here 可用的其他配置选项的信息。我建议您在进行这些更改之前和之后检查您的 jar 文件的 META-INF/MANIFEST.MF 文件,以便您了解那里发生了什么变化。
我正在使用以下命令使用 Maven 创建一个基于 spring 的包
mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes -DarchetypeArtifactId=camel-archetype-spring -DarchetypeVersion=2.15.3 -DgroupId=osgiSpring -DartifactId=osgiSpring -Dversion=1.0-SNAPSHOT -Dpackage=osgiSpring
然后我将这个 Maven 项目导入到 Eclipse 中,只需将 'camel-context.xml' 更改为
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2005-2014 Red Hat, Inc.
Red Hat licenses this file to you under the Apache License, version
2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:C:\input"/>
<to uri="file:C:\output"/>
</route>
</camelContext>
</beans>
之后,我使用 'mvn package' 构建了它,然后将生成的 jar 复制到 Apache Karafs 的部署文件夹中,但 karaf 似乎无法识别该包。
当我 运行 它与 'mvn:camel run' 时,它工作得很好。
它也适用于非 spring 基础捆绑包和激活器。
你的问题是 camel-archetype-spring 只用 camel-maven-plugin 生成 pom.xml 正如你注意到的那样允许你通过 运行 你的代码 'mvn camel:run'.但是,它不会生成正确的 OSGi 清单,因此 Karaf 不会将其识别为 OSGi 包。
解决方案:像这样添加maven-bundle-plugin:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
</plugin>
并像这样设置打包方式:
<packaging>bundle</packaging>
您可以阅读有关 maven-bundle-plugin here 可用的其他配置选项的信息。我建议您在进行这些更改之前和之后检查您的 jar 文件的 META-INF/MANIFEST.MF 文件,以便您了解那里发生了什么变化。