将osgi-bundle部署到ServiceMix的正确方法是什么?

时间:2012-09-25 10:04:58

标签: apache-camel apache-karaf jbossfuse fuseesb apache-servicemix

我尝试为Apache ServiceMix开发一个处理Web服务的入门应用程序。

1)我构建应用程序(使用'mnv install'命令)

2)将其部署到ServiceMix(在服务器控制台上使用'karaf @ root> osgi:install mvn:com.company/ws-test-fuse/1.0.0-SNAPSHOT'命令)

3)观察它是如何安装的('osgi:list')

[ 157] [Installed  ] [            ] [       ] [   60] A Camel Spring Route (1.0.0.SNAPSHOT)

4)我尝试启动应用

karaf@root>osgi:start 157

我明白了:

org.osgi.framework.BundleException: Unresolved constraint in bundle com.company.ws-test-fuse [157]: Unable to resolve 157.0: missing requirement [157.0] package; (&(package=commonj.sdo)(version>=2.1.0)(!(version>=3.0.0)))

安装捆绑包的正确方法是什么,以便自动下载和安装所有maven依赖项?

另外,我是对的,所有依赖项都将作为osgi-bundles部署到osgi-container?

我的POM.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<!-- 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. -->
<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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company</groupId>
    <artifactId>ws-test-fuse</artifactId>
    <packaging>bundle</packaging>
    <version>1.0.0-SNAPSHOT</version>

    <name>A Camel Spring Route</name>
    <url>http://www.myorganization.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <repositories>
        <repository>
            <id>release.fusesource.org</id>
            <name>FuseSource Release Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
        <repository>
            <id>snapshot.fusesource.org</id>
            <name>FuseSource Snapshot Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
        <repository>
            <id>ea.fusesource.org</id>
            <name>FuseSource Early Access Repository</name>
            <url>http://repo.fusesource.com/nexus/content/groups/ea</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>release.fusesource.org</id>
            <name>FuseSource Release Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
        <pluginRepository>
            <id>snapshot.fusesource.org</id>
            <name>FuseSource Snapshot Repository</name>
            <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </pluginRepository>
        <pluginRepository>
            <id>ea.fusesource.org</id>
            <name>FuseSource Early Access Repository</name>
            <url>http://repo.fusesource.com/nexus/content/groups/ea</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>

        <!-- Core -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.9.0.fuse-7-061</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
            <version>2.9.0.fuse-7-061</version>
        </dependency>

        <!-- Apache Cxf -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-cxf</artifactId>
            <version>2.9.0.fuse-7-061</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jetty</artifactId>
            <version>2.9.0.fuse-7-061</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>2.5.0.fuse-7-061</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-databinding-sdo</artifactId>
            <version>2.5.0.fuse-7-061</version>
        </dependency>


        <!-- Apache tuscany SDO -->
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-api-r2.1</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-impl</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-lib</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tuscany.sdo</groupId>
            <artifactId>tuscany-sdo-tools</artifactId>
            <version>1.1.1</version>
        </dependency>

        <!-- SDO Support -->

        <dependency>
            <groupId>org.eclipse.xsd</groupId>
            <artifactId>xsd</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.xsd</groupId>
            <artifactId>xsd</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.emf</groupId>
            <artifactId>ecore</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.emf</groupId>
            <artifactId>ecore-change</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.emf</groupId>
            <artifactId>ecore-xmi</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.emf</groupId>
            <artifactId>common</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.emf</groupId>
            <artifactId>codegen-ecore</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.emf</groupId>
            <artifactId>codegen</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>backport-util-concurrent</groupId>
            <artifactId>backport-util-concurrent</artifactId>
            <version>3.0</version>
        </dependency>


        <!-- logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>

        <!-- testing -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test</artifactId>
            <version>2.9.0.fuse-7-061</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <defaultGoal>install</defaultGoal>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

            <!-- allows the route to be ran via 'mvn camel:run' -->
            <plugin>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-maven-plugin</artifactId>
                <version>2.9.0.fuse-7-061</version>
            </plugin>

            <!-- Maven bundle plugin -->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Import-Package>*,org.apache.camel.osgi</Import-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

2 个答案:

答案 0 :(得分:4)

另一种方法是使用FAB部署到ServiceMix(您需要安装FAB)/ Fuse ESB(FAB附带)。

FAB能够了解您的maven pom.xml文件,并在部署时部署所需的捆绑包。我发布了一些链接,了解更多详情和视频: http://www.davsclaus.com/2012/08/osgi-deployment-made-easy-with-fab.html

另一种方法是创建features.xml文件,并使用功能安装您的应用程序。然后在features文件中,您可以指定应用程序所需的osgi包。您可以参考其他功能等。例如,您可以使用单个命令安装Camel组件。例如,要安装Camel FTP组件,您可以运行:

features:install camel-ftp

因此,如果您的应用程序具有某项功能,则可以执行类似操作。

答案 1 :(得分:2)

Karaf不会解析您的pom.xml,要解决依赖关系,您必须使用以下功能手动安装它们:install或bundle:install。 F.ex.在你的情况下

bundle:install mvn:org.eclipse.persistence/com.springsource.commonj.sdo/2.1.1