简体   繁体   English

Quartz Scheduler和Karaf上的使用依赖关系未启动OSGi捆绑包

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

I am trying to use Quartz Scheduler on Apache Karaf : 我正在尝试在Apache Karaf上使用Quartz Scheduler:

I used Scheduler example on Apache Karaf Github page . 我在Apache Karaf Github页面上使用了Scheduler示例。

On my IDE, I executed an example and it works fine but I can not install and start the bundle under in Karaf. 在我的IDE上,我执行了一个示例,并且运行正常,但是无法在Karaf中安装和启动该捆绑包。

An here's the POM Import and Export of packages : 这是软件包的POM导入和导出:

    <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. 问题是Karaf导入程序包和排除项。 Here's Karaf logs : 这是Karaf日志:

    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

Thank you for your help, Wrapping the Quartz jar can help to resolve this problem and use the dependency as a jar. 感谢您的帮助,包装Quartz jar可以帮助解决此问题并将依赖项用作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 : 要将其安装在Karaf中,我们可以将这些命令与wrap前缀一起使用:

 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 我在此页面上得到了答案: Quartz Scheduler和OSGI

I can't answer your question but if it doesn't have to explicitly be the Quartz scheduler you could use the scheduler from the Apache Sling project. 我无法回答您的问题,但是如果不必明确地是Quartz调度程序,则可以使用Apache Sling项目中的调度程序。 It works just fine in Karaf. 它在Karaf中正常工作。 Just install the bundle in any way you want and you are ready to go. 只需以所需的任何方式安装捆绑包,即可开始使用。

A little howto can be found here . 这里可以找到一些方法。

Actually Karaf does have a scheduler out-of-the-box. 实际上,Karaf确实具有开箱即用的调度程序。 Therefore why not use that one. 因此,为什么不使用那个。 It actually is very similar to the one provided by SLING. 实际上,它与SLING提供的非常相似。 To use it the following commands are available: 要使用它,可以使用以下命令:

install via 通过安装

feature:install scheduler

list all scheduled jobs: 列出所有计划的工作:

scheduler:list

schedule a new job: 安排新工作:

scheduler:schedule

for details about the parameters take a look at 有关参数的详细信息,请看

scheduler:schedule --help

for unscheduling a job: 计划外工作:

scheduler:unschedule <name> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM