gpt4 book ai didi

java - osgi 中的 Optaplanner

转载 作者:行者123 更新时间:2023-12-02 02:44:05 25 4
gpt4 key购买 nike

我正在尝试让 optaplanner 6.5.0 在 osgi 环境中工作。我必须安装以下 bundle 才能解决所有依赖项:

OptaPlanner coreorg.optaplanner.core                                                            6.5.0.201610181310
XStream Corexstream 1.4.9
Apache Commons Mathorg.apache.commons.math3 3.4.1
Drools :: Compilerorg.drools.compiler 6.5.0.201610181300
Drools :: Coreorg.drools.core 6.5.0.201610181300
KIE :: Public APIorg.kie.api 6.5.0.201610181259
KIE :: Internalorg.kie.internalapi 6.5.0.201610181259
Protocol Buffer Java APIcom.google.protobuf 2.6.0
mvel2org.mvel2 2.2.8.Final
Apache ServiceMix :: Bundles :: javax.injectorg.apache.servicemix.bundles.javax-inject 1.0.0.2
XML Pull Parsing APIorg.xmlpull.v1 1.1.4.redhat-1
Apache ServiceMix :: Bundles :: xpp3org.apache.servicemix.bundles.xpp3 1.1.4.c
Apache ServiceMix :: Specs :: Activation API 1.4org.apache.servicemix.specs.activation-api-1.1 2.0.0
Apache ServiceMix :: Bundles :: jaxb-xjcorg.apache.servicemix.bundles.jaxb-xjc 2.2.4.1
Apache ServiceMix :: Specs :: JAXB API 2.2org.apache.servicemix.specs.jaxb-api-2.2 2.9.0
Apache ServiceMix :: Specs :: Stax API 1.0org.apache.servicemix.specs.stax-api-1.0 2.9.0
Apache ServiceMix :: Bundles :: jaxb-implorg.apache.servicemix.bundles.jaxb-impl 2.2.11.1
Apache ServiceMix :: Bundles :: reflectionsorg.apache.servicemix.bundles.reflections 0.9.11.1
OptaPlanner persistence commonorg.optaplanner.persistence.common 6.5.0.201610181310
Sling Metrics :: CQ Fragmentcom.github.digital-wonderland.sling-metrics.cq-metrics-fragment 0.1.0
Guava: Google Core Libraries for Javacom.google.guava 18.0.0

在测试一个通过 junit 测试工作的简单示例时,出现以下错误:

java.lang.NoClassDefFoundError: com/google/common/base/Predicate
at org.optaplanner.core.config.domain.ScanAnnotatedClassesConfig.buildSolutionDescriptor(ScanAnnotatedClassesConfig.java:69)
at org.optaplanner.core.config.solver.SolverConfig.buildSolutionDescriptor(SolverConfig.java:278)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:229)
at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:52)
at com.bekaert.handling.allocation.optimizer.impl.OptimizerTest.before(OptimizerTest.java:55)
at com.bekaert.handling.allocation.optimizer.impl.TestAllocationOptimizerImpl.activate(TestAllocationOptimizerImpl.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)[:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)[:1.8.0_25]
at java.lang.reflect.Method.invoke(Unknown Source)[:1.8.0_25]
at org.apache.felix.scr.impl.helper.BaseMethod.invokeMethod(BaseMethod.java:231)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.helper.BaseMethod.access$500(BaseMethod.java:39)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.helper.BaseMethod$Resolved.invoke(BaseMethod.java:624)
at org.apache.felix.scr.impl.helper.BaseMethod.invoke(BaseMethod.java:508)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.helper.ActivateMethod.invoke(ActivateMethod.java:149)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:315)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:127)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:871)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:838)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:850)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:419)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.config.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:376)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.BundleComponentActivator.initialize(BundleComponentActivator.java:172)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.BundleComponentActivator.<init>(BundleComponentActivator.java:120)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:258)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.Activator.access$000(Activator.java:45)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:185)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)[4:org.apache.felix.scr:1.8.2]
at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:479)[4:org.apache.felix.scr:1.8.2]
at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:414)[4:org.apache.felix.scr:1.8.2]
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)[4:org.apache.felix.scr:1.8.2]
at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:443)[4:org.apache.felix.scr:1.8.2]
at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:869)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:790)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:515)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2100)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)[org.apache.felix.framework-4.4.1.jar:]
at aQute.launcher.Launcher.update(Launcher.java:436)[biz.aQute.launcher-latest.jar:]
at aQute.launcher.Launcher$1.run(Launcher.java:194)[biz.aQute.launcher-latest.jar:]
at java.util.TimerThread.mainLoop(Unknown Source)[:1.8.0_25]
at java.util.TimerThread.run(Unknown Source)[:1.8.0_25]
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Predicate not found by org.apache.servicemix.bundles.reflections [205]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)[org.apache.felix.framework-4.4.1.jar:]
at java.lang.ClassLoader.loadClass(Unknown Source)[:1.8.0_25]
... 43 more

我注意到,在 org.apache.servicemix.bundles.reflections 包中,导入包 com.google.common.base 是可选的。这意味着它甚至应该能够在没有那个包的情况下工作?我无法删除 com.google.guava bundle ,因为 org.optaplanner.core bundle 需要它。

我还可以尝试哪些其他方法来实现这项工作?还有其他人已经设法让 optaplanner 在 osgi 环境中工作吗?

最诚挚的问候,西吉

最佳答案

What I noticed is that in the org.apache.servicemix.bundles.reflections bundle the import-package com.google.common.base is optional. This means it should even be able to work without that package?

从理论上讲,这是真的。然而,通常当您看到导入包的 resolution:=Optional 时,它的含义是以下一项或多项:

  • 这是由一个工具生成的,我并没有真正检查它在做什么
  • 这个包仅在某些代码路径上使用,但并不是真正可选的。如果你沿着这些代码路径中的任何一个走下去,它就会在运行时爆炸
  • 我只是想让我的包更容易解析,但并不明白这个包确实是需要的。

根据您看到的问题,我猜测这是仅在某些代码路径上需要该包的情况。

What other things can I try to make this work? Anyone else already managed to get optaplanner working in an osgi environment?

从堆栈跟踪来看,这似乎在配置过程中失败了,因此您可以通过避免损坏的功能来配置问题。您还可以安装实际提供 com.google.common.base 的 bundle ,以满足可选导入的要求。

另一种方法是完全重新打包库,确保您获得正确的 OSGi 元数据。您还可以将其他库(或库的一部分)嵌入到这个重新打包的包中,以限制其导入的包集和/或解决反射类加载导致问题的地方。

关于java - osgi 中的 Optaplanner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44931012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com