0

I created a small project that uses mail Apache Camel Mail. As usual, he started the project and works well, but as soon as I try to run it as a bundle, there is a problem:

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

My file pom.xml looks like this:

<?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>

The file 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();
}
}

How can I resolve this error? Thank!

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
R.Skidan
  • 3
  • 3
  • Is it because of `|**org**.camel.mail` vs. `**com**.camel.mail.Activator`? And, BTW, dots in the `` are unusual, I'd use hyphens instead. – Gerold Broser Jul 02 '16 at 16:06
  • I changed | to com.camel.mail com.camel.mail, but it does not solve the problem – R.Skidan Jul 02 '16 at 16:25
  • Maybe it's because in the jar file does not include any dependent libraries, such as osgi, camel, etc., because the final jar file size is just 7K – R.Skidan Jul 02 '16 at 17:36
  • Have you seen these, atm, two questions: http://stackoverflow.com/search?q=osgi+java.lang.ClassNotFoundException%3A+org.osgi.framework.BundleActivator+not+found+by already? Maybe there's some hint in them. – Gerold Broser Jul 02 '16 at 17:39
  • That's the idea of running a bundle in an OSGi, or any, container: The dependencies are usually supplied by the container. – Gerold Broser Jul 02 '16 at 17:44
  • @GeroldBroser I have seen these questions, but they did not help me. Is my file pom.hml correct? – R.Skidan Jul 02 '16 at 17:54
  • It seems OK at first sight. Let me try it in a real project here. But this can take a while – Euro 2016 quarter final in an hour. :) – Gerold Broser Jul 02 '16 at 18:04
  • @GeroldBroser Sure, I will wait. One I can not solve the problem. Thank you! – R.Skidan Jul 02 '16 at 18:08
  • I noticed that if you remove this line: ctx = new OsgiDefaultCamelContext(bundleContext); and comment all the code all runs without errors – R.Skidan Jul 03 '16 at 13:11
  • And falls in error to her at: 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].) java.lang.NoClassDefFoundError: org/apache/camel/CamelContext at java.lang.Class.getDeclaredConstructors0(Native Method) – R.Skidan Jul 03 '16 at 13:12
  • I didn't have the time yet to try it live here, but I found the following "[_The loader inside each bundle can only load classes that are either inside the bundle, or explicitly imported from another bundle._ \[...\] _You must import every package used by your bundle, with the exception of packages that are already part of your bundle and packages that begin with “java.”_](http://enroute.osgi.org/faq/class-not-found-exception.html)". You exclude `!org.osgi.framework` from being imported, so it's comprehensible that `org.osgi.framework.BundleActivator` cannot be found by your bundle, isn't it. – Gerold Broser Jul 03 '16 at 13:32
  • @GeroldBroser I added in pom.xml org.apache.camel,org.osgi.framework,org.apache.camel.camel-osgi – R.Skidan Jul 03 '16 at 14:00
  • but I've error: org.osgi.framework.BundleException: Unable to resolve org.camel.mail.org.camel.mail [4](R 4.0): missing requirement [org.camel.mail.org.camel.mail [4](R 4.0)] osgi.wiring.package; (osgi.wiring.package=org.apache.camel.camel-osgi) Unresolved requirements: [[org.camel.mail.org.camel.mail [4](R 4.0)] osgi.wiring.package; (osgi.wiring.package=org.apache.camel.camel-osgi)]. But I can not understand what he wants from me, because I have all the packages added to the import – R.Skidan Jul 03 '16 at 14:00
  • See [Apache Felix Maven Bundle Plugin (BND), ``](https://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html#import-package): "_This header rarely has to be explicitly specified._". What if you remove the declaration altogether, such using the default "`*`". (Remember Maven's core concept: _Convention over configuration._ ;) – Gerold Broser Jul 03 '16 at 14:06
  • @GeroldBroser, Now,I left only two lines: instructions> com.camel.mail.roma com.camel.mail.roma.Activator .And changed TestCamel com.TestCamel – R.Skidan Jul 03 '16 at 14:16
  • But, I have error: org.osgi.framework.BundleException: Unable to resolve TestCamel.com.TestCamel [4](R 4.0): missing requirement [TestCamel.com.TestCamel [4](R 4.0)] osgi.wiring.package; (osgi.wiring.package=org.apache.camel.osgi) [caused by: Unable to resolve org.apache.camel.camel-osgi [9](R 9.0): missing requirement [org.apache.camel.camel-osgi [9](R 9.0)] osgi.wiring.package; (&(osgi.wiring.package=org.apache.camel)(version>=2.2.0)(!(version>=2.2.1)))] Unresolved requirements: – R.Skidan Jul 03 '16 at 14:16
  • `` shouldn't be necessary either if you only export packages from your `/src`. Why do you change vital identifiers (groupId, artifactId, package names) in the middle of troubleshooting? This doesn't make it clearer. – Gerold Broser Jul 03 '16 at 15:04
  • I changed pom.xml on TestCamel com.camel.mail.Activator * , and return groupId, artifactId, package names – R.Skidan Jul 03 '16 at 15:21
  • but I've error rg.osgi.framework.BundleException: Unable to resolve TestCamel [4](R 4.0): missing requirement [TestCamel [4](R 4.0)] osgi.wiring.package; (osgi.wiring.package=com.camel.mail) Unresolved requirements: [[TestCamel [4](R 4.0)] osgi.wiring.package; (osgi.wiring.package=com.camel.mail)] I do not understand, because I have it import all packages – R.Skidan Jul 03 '16 at 15:22
  • @GeroldBroser Please, You can try to run it at home? Here's the code to githab https://github.com/roma-sk3/CamelTestOsgi – R.Skidan Jul 03 '16 at 15:39
  • I changed my pom.xml ${project.artifactId} * * com.camel.mail.Activator *,!com.ibm.uvm.tools – R.Skidan Jul 03 '16 at 19:17
  • The error disappeared, but was swearing on the duplicate. What's wrong? Auto-properties install: file:/D:/Projects/CamelMail/target/com.camel.mail-1.0.jar (org.osgi.framework.BundleException: Duplicate import: com.ibm.uvm.tools) Auto-properties start: file:/D:/Projects/CamelMail/target/com.camel.mail-1.0.jar (org.osgi.framework.BundleException: Duplicate import: com.ibm.uvm.tools) – R.Skidan Jul 03 '16 at 19:17

0 Answers0