不要运行bundle org.osgi.framework.BundleException

时间:2016-07-02 15:15:05

标签: java maven apache-camel apache-felix osgi-bundle

我创建了一个使用邮件Apache Camel Mail的小项目。像往常一样,他启动了这个项目并运行良好,但是一旦我尝试将其作为一个捆绑包运行,就会出现问题:

java.lang.NoClassDefFoundError: org/osgi/framework/BundleActivator
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2370)
ERROR: Bundle org.camel.mail.org.camel.mail [4] Error starting file:/D:/Projects/CamelMail/target/org.camel.mail-1.0.jar (org.osgi.framework.BundleException: Activator start error in bundle org.camel.mail.org.camel.mail [4].)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2154)
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1542)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1415)
at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4468)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2221)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2144)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.osgi.framework.BundleActivator not found by org.camel.mail.org.camel.mail [4]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1574)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 15 more

我的文件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">
<modelVersion>4.0.0</modelVersion>

<groupId>org.camel.mail</groupId>
<artifactId>org.camel.mail</artifactId>
<version>1.0</version>
<packaging>bundle</packaging>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
                    <Bundle-Name>English dictionary</Bundle-Name>
                    <Bundle-Description>A bundle that registers an English dictionary service</Bundle-Description>
                    <Bundle-Vendor>Apache-Felix</Bundle-Vendor>
                    <Bundle-Version>1.0.0</Bundle-Version>
                    <Bundle-Activator>com.camel.mail.Activator</Bundle-Activator>
                    <Embed-Transitive>true</Embed-Transitive>
                    <Import-Package>!org.apache.camel;!org.osgi.framework;!org.apache.felix</Import-Package>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-mail</artifactId>
        <version>${camel-mail.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core-osgi</artifactId>
        <version>2.17.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-osgi</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>6.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.felix</groupId>
        <artifactId>org.apache.felix.eventadmin</artifactId>
        <version>1.4.6</version>
    </dependency>
</dependencies>
<properties>
    <camel-mail.version>2.17.1</camel-mail.version>
    <!--<log4j-core.version>2.6.1</log4j-core.version>-->
</properties>

文件com.camel.mail.Activator

public class Activator implements BundleActivator {

private CamelContext ctx = null;

public void start(BundleContext bundleContext) throws Exception {
    ctx = new OsgiDefaultCamelContext(bundleContext);
    ctx.addRoutes(new RouteBuilder() {
        public void configure() {
            Processor myProcessor = new Processor()
            {
                public void process (Exchange exchange)
                {
                    exchange.getIn().getBody(String.class);
                }
            };

            from("imaps://imap.yandex.ru?username=***&password=*****&delete=false&peek=false&unseen=true&consumer.delay=6000&closeFolder=false&disconnect=false")
                    .process(myProcessor);

        }
    });

    ctx.start();
}

public void stop(BundleContext bundleContext) throws Exception {
    ctx.stop();
}
}

如何解决此错误?谢谢!

0 个答案:

没有答案