2015-09-08 23 views
2

我是Apache camel的新手,剛試圖用RouteBuilder創建一個Route,但只要我有一個類擴展RouterBuilder,當我嘗試安裝時出現此錯誤在Apache中karaf這束:apache camel未解決的束縛當在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> 
+0

什麼是你的OSGI捆綁號碼91?你有沒有檢查'org.apache.camel.builder'的缺失要求? – SubOptimal

+0

我只有一個OSGi包,它是由3個部分組成的那個 - 這是91號的那個包。'org.apache.camel.builder'在我得到的xml中的camel-core依賴中 – Milla

回答

4

您正在失蹤camel-core依賴於您的Karaf安裝。如果您檢查了osgi-1.0-SNAPSHOT.jar包中的META-INF/MANIFEST.MF文件,則可以看到Import-Packages部分中有一行說org.apache.camel.builder與所有其他包您的包需要運行。

現在,當您部署您的軟件包時,必須滿足清單文件中的所有這些導入,否則您將獲得這些軟件包連接例外。由於你在你的pom.xml中有駱駝核心(更確切地說,因爲你已經將Java代碼導入到駱駝核心類中),所以你必須在Karaf中也有這些類。自己的類將是捆綁罐內既然你已經定義:

<Export-Package> 
    osgi*;version=${project.version} 
</Export-Package> 

Karaf將提供org.osgi.core和你將不必自行安裝。


解決方案1 ​​:您可以通過插入下面的Karaf控制檯手動安裝駱駝核心

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安裝和複製目標/*.kar文件到Karaf部署文件夾Karaf將爲您安裝camel-core。在此之後,您的軟件包安裝將成功。


請注意,當您登錄到System.out時,它不會出現在Karaf控制檯日誌中,因此不要期望在那裏看到這些消息。您可以使用例如Log4j記錄器在那裏。