在 apache karaf 中安装时,apache camel 在捆绑包中未解决的约束
apache camel unresolved constraint in bundle when installing in apache karaf
我是 Apache camel 的新手,刚刚尝试使用 RouteBuilder 构建路由,但是当我得到 class 扩展 RouterBuilder 时,当我尝试在 Apache karaf 中安装该包时出现此错误:
2015-09-08 14:54:49,227 | WARN | raf-3.0.4/deploy | fileinstall
| 7 - org.apache.felix.fileinstall - 3.5.0 | Error while starting bundle:
file:/C:/apache-karaf-3.0.4/deploy/osgi-1.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Unresolved constraint in bundle osgi [91]: U
nable to resolve 91.0: missing requirement [91.0] osgi.wiring.package; (&(osgi.w
iring.package=org.apache.camel.builder)(version>=2.14.0)(!(version>=3.0.0)))
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:397
4)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)[org.apa
che.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.
apache.felix.framework-4.2.1.jar:]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(Di
rectoryWatcher.java:1245)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(D
irectoryWatcher.java:1217)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(Dire
ctoryWatcher.java:509)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(Direct
oryWatcher.java:358)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryW
atcher.java:310)[7:org.apache.felix.fileinstall:3.5.0]
现在我只有那2个类
package osgi;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public void start(BundleContext context) {
System.out.println("Starting the bundle");
}
public void stop(BundleContext context) {
System.out.println("Stopping the bundle");
}
}
package osgi;
import org.apache.camel.builder.RouteBuilder;
public class TimerRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
// TODO Auto-generated method stub
}
}
这是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF 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.
-->
<modelVersion>4.0.0</modelVersion>
<groupId>osgi</groupId>
<artifactId>osgi</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>osgi Bundle</name>
<description>osgi OSGi bundle project.</description>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.14.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator>osgi.Activator</Bundle-Activator>
<Export-Package>
osgi*;version=${project.version}
</Export-Package>
<Import-Package>
*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
您在 Karaf 安装中缺少 camel-core 依赖项。如果您检查 osgi-1.0-SNAPSHOT.jar 包中的 META-INF/MANIFEST.MF 文件,您可以看到 Import-Packages 部分中有一行显示 org.apache.camel.builder 与您的捆绑包所需的所有其他包到 运行。
现在,当您部署捆绑包时,必须满足清单文件中的所有这些导入,否则您会遇到捆绑包连接异常。由于您的 pom.xml 中有 camel-core(更准确地说,因为您的 Java 代码中有导入到 camel-core 类),所以您必须有那些 类 也存在于卡拉夫。你自己的 类 将在那个 bundle jar 中,因为你定义了:
<Export-Package>
osgi*;version=${project.version}
</Export-Package>
Karaf 会提供org.osgi.core,您不必自己安装。
解决方案 1:您可以通过在 Karaf 控制台中插入以下内容来手动安装 camel-core:
feature:repo-add mvn:org.apache.camel.karaf/apache-camel/2.14.3/xml/features
feature:install camel-core
在此之后,您的捆绑包安装将会成功。
解决方案 2:您可以创建 Karaf 存档 (.kar),它将所有必需的依赖项组合到一个您可以部署的文件中。使用如下结构创建新的 Maven 项目:
.
├── pom.xml
└── src
└── main
└── feature
└── feature.xml
其中pom.xml是
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>osgi-example-kar</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>kar</packaging>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>3.0.2</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
而feature.xml是
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.1" name="osgi-example-features">
<repository>mvn:org.apache.camel.karaf/apache-camel/2.14.3/xml/features</repository>
<feature name="osgi-example-features" version="1.0-SNAPSHOT"
description="Features for running simple OSGi example.">
<feature version="2.14.3">camel-core</feature>
</feature>
</features>
当您 运行 mvn install 并将 target/*.kar 文件复制到 Karaf 部署文件夹时,Karaf 将为您安装 camel-core。在此之后,您的捆绑包安装将成功。
请注意,当您登录 System.out 时,它不会出现在 Karaf 控制台日志中,因此不要指望在那里看到这些消息。你可以使用例如那里有 Log4j 记录器。
我是 Apache camel 的新手,刚刚尝试使用 RouteBuilder 构建路由,但是当我得到 class 扩展 RouterBuilder 时,当我尝试在 Apache karaf 中安装该包时出现此错误:
2015-09-08 14:54:49,227 | WARN | raf-3.0.4/deploy | fileinstall
| 7 - org.apache.felix.fileinstall - 3.5.0 | Error while starting bundle:
file:/C:/apache-karaf-3.0.4/deploy/osgi-1.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Unresolved constraint in bundle osgi [91]: U
nable to resolve 91.0: missing requirement [91.0] osgi.wiring.package; (&(osgi.w
iring.package=org.apache.camel.builder)(version>=2.14.0)(!(version>=3.0.0)))
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:397
4)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)[org.apa
che.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.
apache.felix.framework-4.2.1.jar:]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(Di
rectoryWatcher.java:1245)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(D
irectoryWatcher.java:1217)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(Dire
ctoryWatcher.java:509)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(Direct
oryWatcher.java:358)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryW
atcher.java:310)[7:org.apache.felix.fileinstall:3.5.0]
现在我只有那2个类
package osgi;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public void start(BundleContext context) {
System.out.println("Starting the bundle");
}
public void stop(BundleContext context) {
System.out.println("Stopping the bundle");
}
}
package osgi;
import org.apache.camel.builder.RouteBuilder;
public class TimerRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
// TODO Auto-generated method stub
}
}
这是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF 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.
-->
<modelVersion>4.0.0</modelVersion>
<groupId>osgi</groupId>
<artifactId>osgi</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>osgi Bundle</name>
<description>osgi OSGi bundle project.</description>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.14.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator>osgi.Activator</Bundle-Activator>
<Export-Package>
osgi*;version=${project.version}
</Export-Package>
<Import-Package>
*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
您在 Karaf 安装中缺少 camel-core 依赖项。如果您检查 osgi-1.0-SNAPSHOT.jar 包中的 META-INF/MANIFEST.MF 文件,您可以看到 Import-Packages 部分中有一行显示 org.apache.camel.builder 与您的捆绑包所需的所有其他包到 运行。
现在,当您部署捆绑包时,必须满足清单文件中的所有这些导入,否则您会遇到捆绑包连接异常。由于您的 pom.xml 中有 camel-core(更准确地说,因为您的 Java 代码中有导入到 camel-core 类),所以您必须有那些 类 也存在于卡拉夫。你自己的 类 将在那个 bundle jar 中,因为你定义了:
<Export-Package>
osgi*;version=${project.version}
</Export-Package>
Karaf 会提供org.osgi.core,您不必自己安装。
解决方案 1:您可以通过在 Karaf 控制台中插入以下内容来手动安装 camel-core:
feature:repo-add mvn:org.apache.camel.karaf/apache-camel/2.14.3/xml/features
feature:install camel-core
在此之后,您的捆绑包安装将会成功。
解决方案 2:您可以创建 Karaf 存档 (.kar),它将所有必需的依赖项组合到一个您可以部署的文件中。使用如下结构创建新的 Maven 项目:
.
├── pom.xml
└── src
└── main
└── feature
└── feature.xml
其中pom.xml是
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>osgi-example-kar</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>kar</packaging>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>3.0.2</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
而feature.xml是
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.1" name="osgi-example-features">
<repository>mvn:org.apache.camel.karaf/apache-camel/2.14.3/xml/features</repository>
<feature name="osgi-example-features" version="1.0-SNAPSHOT"
description="Features for running simple OSGi example.">
<feature version="2.14.3">camel-core</feature>
</feature>
</features>
当您 运行 mvn install 并将 target/*.kar 文件复制到 Karaf 部署文件夹时,Karaf 将为您安装 camel-core。在此之后,您的捆绑包安装将成功。
请注意,当您登录 System.out 时,它不会出现在 Karaf 控制台日志中,因此不要指望在那里看到这些消息。你可以使用例如那里有 Log4j 记录器。