【问题标题】:Spring based bundle on apache karaf doesn't workapache karaf 上基于 Spring 的捆绑包不起作用
【发布时间】:2015-12-06 12:48:25
【问题描述】:

我正在使用以下命令使用 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' 运行它时,它工作得很好。

它还适用于带有 Activator 的非基于弹簧的捆绑包。

【问题讨论】:

  • 您可以在日志中发布错误吗?
  • 如果我有一个我会的......正如我所说的,在将该 jar 复制到部署文件夹后绝对没有任何反应
  • 好吧,没有日志,我所能建议的就是尝试这里所说的,在 wrap deployer karaf.apache.org/manual/latest-2.2.x/users-guide/deployer.html 可能问题是不适合 karaf 的工件,但无济于事它关于应该使用哪个工件。

标签: spring maven apache-camel osgi apache-karaf


【解决方案1】:

您的问题是 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 文件,以便掌握那里的更改。

【讨论】:

    猜你喜欢
    • 2015-05-22
    • 2015-12-05
    • 2012-04-13
    • 2014-05-04
    • 1970-01-01
    • 2012-08-29
    • 1970-01-01
    • 2012-03-14
    • 2022-11-07
    相关资源
    最近更新 更多