我正在尝试使用Maven创建OSGI捆绑包。我无法正确捆绑JAR

时间:2019-02-21 12:34:01

标签: java maven osgi apache-felix apache-servicemix

我遇到了异常。我正在使用servicemix运行捆绑软件。我认为我没有正确导入和导出软件包,这就是我得到类未发现异常的原因。我的包裹结构是com.born.XXXX。请帮助我正确构建捆绑包。

Caused by: java.lang.NoClassDefFoundError: org/apache/camel/Processor
        at java.lang.ClassLoader.defineClass1(Native Method)[:1.8.0_162]
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)[:1.8.0_162]
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2310)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2094)
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1518)
        at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:79)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1958)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_162]
        at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1925)[org.apache.felix.framework-5.6.2.jar:]
        at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:978)
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.loadClass(BlueprintContainerImpl.java:467)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.cxf.bus.blueprint.BlueprintBeanLocator.getClassForMetaData(BlueprintBeanLocator.java:73)
        at org.apache.cxf.bus.blueprint.BlueprintBeanLocator.getClassForMetaData(BlueprintBeanLocator.java:82)
        at org.apache.cxf.bus.blueprint.BlueprintBeanLocator.getBeansOfType(BlueprintBeanLocator.java:121)
        at org.apache.cxf.bus.extension.ExtensionManagerBus.initialize(ExtensionManagerBus.java:280)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_162]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_162]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_162]
        at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_162]
        at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:299)
        at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:980)
        at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:736)
        ... 28 more
Caused by: java.lang.ClassNotFoundException: org.apache.camel.Processor not found by ProductRouter [222]
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1550)[org.apache.felix.framework-5.6.2.jar:]
        at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:79)[org.apache.felix.framework-5.6.2.jar:]
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1958)[org.apache.felix.framework-5.6.2.jar:]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_162]
        ... 50 more  

这是我的pom.xml文件。     http://maven.apache.org/xsd/maven-4.0.0.xsd“>

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>oktopus-integration</artifactId>
        <groupId>com.born</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <groupId>com.born</groupId>
    <artifactId>ProductRouter</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>bundle</packaging>

    <name>ProductRouter Blueprint Bundle</name>
    <description>ProductRouter OSGi blueprint bundle project.</description>

<dependencies>
        <dependency>
            <groupId>com.born</groupId>
            <artifactId>oktopus-common</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <!-- <scope>provided</scope> -->
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-blueprint</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.camel/camel-cxf -->
    <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-cxf</artifactId>
    <version>2.23.1</version>
    </dependency>
<dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jackson</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </dependency>   
        <!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk16 -->
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk16</artifactId>
        <version>1.45</version>
    </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-ws-security</artifactId>
        </dependency>
                        <!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20160212</version>
</dependency>





    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.0</version>
    </dependency>

    <dependency>
    <groupId>org.apache.axis</groupId>
    <artifactId>axis</artifactId>
    <version>1.4</version>
</dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-bundle-jaxrs -->
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-bundle-jaxrs</artifactId>
    <version>2.6.0</version>
</dependency>


    </dependencies>


    <build>
        <plugins>
             <!--  ERP JAXB creation services -->
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.14.0</version>
                <executions>
                    <execution>
                        <id>Netsuite services</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <wsdl>true</wsdl>
                            <xmlschema>false</xmlschema>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>*.wsdl</include>
                            </schemaIncludes>
                            <bindingDirectory>src/main/resources/wsdl</bindingDirectory>
                            <bindingIncludes>
                                <include>edu.xjb</include>
                            </bindingIncludes>
                            <schemaLanguage>WSDL</schemaLanguage>
                            <generatePackage>com.born.netsuite.stub</generatePackage>
                            <forceRegenerate>true</forceRegenerate>
                            <generateDirectory>gensrc</generateDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>   
           <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>

                <extensions>true</extensions>
                <configuration>
                    <instructions>

                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Version>${project.version}</Bundle-Version>
                        <Export-Package>"!com.born,*";version=${project.version}</Export-Package>

                        <Import-Package> "!com.born,*"</Import-Package>
                        <!-- <Embed-Dependency>*;scope= *</Embed-Dependency> -->
                         <Embed-Dependency>oktopus-integration,commons-lang,jaxws-api,json</Embed-Dependency>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

下面是我的MANIFEST.IMF文件。

Manifest-Version: 1.0
Bnd-LastModified: 1550813093689
Build-Jdk: 1.8.0_162
Built-By: Vishal.jagdale
Bundle-Blueprint: OSGI-INF/blueprint/productDataRouter.xml
Bundle-ClassPath: .,json-20160212.jar
Bundle-Description: ProductRouter OSGi blueprint bundle project.
Bundle-ManifestVersion: 2
Bundle-Name: ProductRouter Blueprint Bundle
Bundle-SymbolicName: ProductRouter
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: oktopus-integration,commons-lang,jaxws-api,json
Embedded-Artifacts: json-20160212.jar;g="org.json";a="json";v="2016021
 2"
Export-Package: com.born.netsuite.stub;version="1.0.0.SNAPSHOT";uses:=
 "javax.xml.bind.annotation,javax.xml.datatype",com.born.oktopus.commo
 n.data;version="1.0.0.SNAPSHOT";uses:="javax.xml.bind.annotation",com
 .born.oktopus.esb.common;version="1.0.0.SNAPSHOT",com.born.oktopus.es
 b.common.processor;version="1.0.0.SNAPSHOT";uses:="org.apache.camel",
 com.born.oktopus.esb.data;version="1.0.0.SNAPSHOT";uses:="org.apache.
 camel.dataformat.bindy.annotation",com.born.oktopus.product.client;ve
 rsion="1.0.0.SNAPSHOT";uses:="javax.security.auth.callback",com.born.
 oktopus.product.controller;version="1.0.0.SNAPSHOT";uses:="javax.ws.r
 s",com.born.oktopus.product.processor;version="1.0.0.SNAPSHOT";uses:=
 "org.apache.camel",com.born.oktopus.product.routes;version="1.0.0.SNA
 PSHOT";uses:="org.apache.camel.builder",com.born.oktopus.rest;version
 ="1.0.0.SNAPSHOT";uses:="javax.xml.bind.annotation",com.born.oktopus.
 wsdl.data;version="1.0.0.SNAPSHOT";uses:="javax.xml.bind.annotation,j
 avax.xml.datatype"
Import-Package: javax.security.auth.callback,
 javax.ws.rs;version="[2.0,3)",javax.xml.bind.annotation;version="[2.2
 ,3)",javax.xml.datatype,org.apache.camel;version="[2.16,3)",org.apach
 e.camel.builder;version="[2.16,3)",org.apache.camel.dataformat.bindy.
 annotation;version="[2.16,3)",org.apache.camel.model;version="[2.16,3
 )",org.apache.camel.spi;version="[2.16,3)",org.apache.cxf.interceptor
 ;version="[3.1,4)",org.apache.cxf.jaxrs.provider;version="[3.1,4)",or
 g.apache.cxf.ws.security.wss4j;version="[3.1,4)",org.apache.wss4j.com
 mon.ext;version="[2.1,3)",org.osgi.service.blueprint;version="[1.0.0,
 2.0.0)"
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-4.1.0.201810181252

1 个答案:

答案 0 :(得分:1)

当我需要在Servicemix中将JAR转换为包时,我使用:

./bin/servicemix

osgi:install -s wrap:file:////"jar_location Ex: /lib/ojdbc6-13.jar"

执行关闭命令,选择“是”选项。