Search code examples
javamavenquartz-schedulerapache-karafosgi-bundle

Quartz Scheduler and usage dependencies on Karaf not starting an OSGi bundle


I am trying to use Quartz Scheduler on Apache Karaf :

I used Scheduler example on Apache Karaf Github page.

On my IDE, I executed an example and it works fine but I can not install and start the bundle under in Karaf.

An here's the POM Import and Export of packages :

    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
    <Bundle-Version>${project.version}</Bundle-Version>
    <Export-Package>
         com.schedule*;version=${project.version}
    </Export-Package>                        
    <Import-Package>
         !com.mchange.*,
         !oracle.*,
         !org.quartz.management,
         !weblogic.*,
         !javax.transaction,
         *
    </Import-Package>
    <Private-Package>
         org.apache.karaf.scheduler.core,
         org.apache.karaf.scheduler.command.*,
         org.quartz,
         org.quartz.core.*,
         org.quartz.listeners.*,
         org.quartz.impl.*,
         org.quartz.spi.*,
         org.quartz.simpl.*,
         org.quartz.utils.*,
     </Private-Package>

The problem is Karaf Import packages and exclusions. Here's Karaf logs :

    Caused by: java.lang.NoClassDefFoundError: org/quartz/ee/jta/JTAAnnotationAwareJobRunShellFactory
    at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1204)
    at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1519)
    at com.soprahr.hub.bc.schedule.core.SimpleSchedule.init(SimpleSchedule.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    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)
    ... 38 more
    Caused by: java.lang.ClassNotFoundException: org.quartz.ee.jta.JTAAnnotationAwareJobRunShellFactory not found by com.schedule. [311]
    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)
    ... 48 more

Solution

  • Thank you for your help, Wrapping the Quartz jar can help to resolve this problem and use the dependency as a jar. That's why we need these dependencies :

       <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.quartz</artifactId>
            <version>2.2.3_1</version>
        </dependency>
    
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.3</version>
        </dependency>
    
        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.2</version>
        </dependency>
    

    And to install it in Karaf, we can use these commands with wrap prefix :

     bundle:install wrap:mvn:c3p0/c3p0/0.9.1.2
     bundle:install mvn:org.quartz-scheduler/quartz/2.2.2
     bundle:install wrap:mvn:org.quartz-scheduler/quartz-jobs/2.2.2
    

    I got my answer on this page : Quartz scheduler and OSGI