gpt4 book ai didi

java - OSGi ClassNotFoundException 异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:54:06 25 4
gpt4 key购买 nike

我正在尝试运行 Modular Java 书中的示例并面临 ClassNotFoundException。错误的要点是我有 2 个 bundle 。

Bundle 1 称为索引。Bundle 2 是 Compass 项目的打包包。

Bundle 1 使用 Bundle 2 并在其 list 的“Import-Package” header 中声明了它使用的 Bundle 2 中的包。 Bundle 2 也导出相同的包。

Index(Bundle 1)使用的 Bundle 2 的类,调用 Bundle 2 内部的更多类。这些类的包也由 Bundle 2 导出。但是每当我在 Felix 上部署这些(使用 Pax-runner)时,启动都会失败并出现以下错误。

[FelixDispatchQueue] DEBUG main-findmyjar.index - BundleEvent STOPPED - main-findmyjar.index
ERROR: Bundle main-findmyjar.index [7] Error starting file:bundles/main-findmyjar.index_1.0.0.SNAPSHOT.jar (org.osgi.framework.BundleException: Activator start error in bundle main-findmyjar.index [7].)
org.compass.core.config.ConfigurationException: Failed to instantiate [org.compass.core.config.binding.metadata.AsmMetaDataReader], please verify class type at setting [compass.scanner.reader]; nested exception is java.lang.ClassNotFoundException: org.compass.core.config.binding.metadata.AsmMetaDataReader
java.lang.ClassNotFoundException: org.compass.core.config.binding.metadata.AsmMetaDataReader
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.compass.core.util.ClassUtils.forName(ClassUtils.java:90)
at org.compass.core.config.CompassSettings.getSettingAsInstance(CompassSettings.java:304)
at org.compass.core.config.binding.metadata.MetaDataReaderFactory.getMetaDataReader(MetaDataReaderFactory.java:35)
at org.compass.core.config.binding.AbstractClassMetaDataMappingBinding.setUpBinding(AbstractClassMetaDataMappingBinding.java:24)
at org.compass.annotations.config.binding.AnnotationsMappingBinding.setUpBinding(AnnotationsMappingBinding.java:93)
at org.compass.core.config.CompassMappingBinding.setUpBinding(CompassMappingBinding.java:56)
at org.compass.core.config.CompassConfiguration.getMappingBinding(CompassConfiguration.java:121)
at org.compass.core.config.CompassConfiguration.addClass(CompassConfiguration.java:500)
at org.gt.osgi.findmyjar.index.internal.Activator.getCompass(Activator.java:40)
at org.gt.osgi.findmyjar.index.internal.Activator.start(Activator.java:35)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1977)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1895)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1191)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)
at java.lang.Thread.run(Thread.java:662)
[FelixDispatchQueue] DEBUG main-findmyjar.index - FrameworkEvent ERROR - main-findmyjar.index
org.osgi.framework.BundleException: Activator start error in bundle main-findmyjar.index [7].
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2027)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1895)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1191)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.compass.core.config.ConfigurationException: Failed to instantiate [org.compass.core.config.binding.metadata.AsmMetaDataReader], please verify class type at setting [compass.scanner.reader]; nested exception is java.lang.ClassNotFoundException: org.compass.core.config.binding.metadata.AsmMetaDataReader
at org.compass.core.config.CompassSettings.getSettingAsInstance(CompassSettings.java:306)
at org.compass.core.config.binding.metadata.MetaDataReaderFactory.getMetaDataReader(MetaDataReaderFactory.java:35)
at org.compass.core.config.binding.AbstractClassMetaDataMappingBinding.setUpBinding(AbstractClassMetaDataMappingBinding.java:24)
at org.compass.annotations.config.binding.AnnotationsMappingBinding.setUpBinding(AnnotationsMappingBinding.java:93)
at org.compass.core.config.CompassMappingBinding.setUpBinding(CompassMappingBinding.java:56)
at org.compass.core.config.CompassConfiguration.getMappingBinding(CompassConfiguration.java:121)
at org.compass.core.config.CompassConfiguration.addClass(CompassConfiguration.java:500)
at org.gt.osgi.findmyjar.index.internal.Activator.getCompass(Activator.java:40)
at org.gt.osgi.findmyjar.index.internal.Activator.start(Activator.java:35)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1977)
... 4 more
Caused by: java.lang.ClassNotFoundException: org.compass.core.config.binding.metadata.AsmMetaDataReader
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.compass.core.util.ClassUtils.forName(ClassUtils.java:90)
at org.compass.core.config.CompassSettings.getSettingAsInstance(CompassSettings.java:304)
... 14 more
[FelixDispatchQueue] DEBUG org.apache.felix.framework - BundleEvent STARTED - org.apache.felix.framework
[FelixDispatchQueue] DEBUG org.apache.felix.framework - FrameworkEvent STARTED - org.apache.felix.framework

有什么问题的线索吗?

这是 list 。

Manifest-Version: 1.0
Export-Package: org.gt.osgi.findmyjar.index;uses:="org.gt.osgi.findmyj
ar.domain";version="1.0.0.SNAPSHOT"
Private-Package: org.gt.osgi.findmyjar.index.internal
Ignore-Package: org.gt.osgi.findmyjar.index.internal
Built-By: tyagig
Tool: Bnd-0.0.255
Bundle-Name: main-findmyjar.index
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.6.0_32
Bundle-Version: 1.0.0.SNAPSHOT
Bnd-LastModified: 1357910690482
Bundle-ManifestVersion: 2
Bundle-Activator: org.gt.osgi.findmyjar.index.internal.Activator
Bundle-Description: Generated using Pax-Construct
Bundle-SymbolicName: main-findmyjar.index
Import-Package: org.compass.core,org.compass.core.config,org.compass.c
ore.config.binding.metadata,org.gt.osgi.findmyjar.domain;version="1.0
.0.SNAPSHOT",org.gt.osgi.findmyjar.index;version="1.0.0.SNAPSHOT",org
.osgi.framework

最佳答案

似乎您有一个 org.compass.core.util.ClassUtils,它执行一个 Class.forName(),这会导致问题级联。

如果 ClassUtils 在 bundle 2 中并且没有给它明确的类加载器使用,它将默认为 bundle 类加载器。 bundleclassloader 只能实例化 bundle2 可见的类(在整个类图中)。

它尝试加载的设置很可能是 bundle1 中指定的类,该类不可见。

解决方案是在涉及到动态加载类或查看类加载器伙伴机制时,将类加载器从 bundle1 传递到 bundle2。有一个旧article这可能会更清楚地解释这一点。

关于java - OSGi ClassNotFoundException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14279388/

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