2013-01-11 85 views
3

我想從模塊化Java書中運行示例,並面臨ClassNotFoundException。錯誤的要點是我有2捆。OSGi ClassNotFoundException

捆綁1被稱爲索引。 Bundle 2是Compass項目的一攬子包裝。

Bundle 1使用Bundle 2並使用它在其清單中的「Import-Package」標頭中聲明的Bundle 2中使用的包。捆綁軟件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 

任何線索可能是什麼問題?

這是清單。

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 
+0

我們可以看到bundle1和bundle2的清單嗎? – cowls

+0

在這裏找到更多的信息。當Bundle 1調用Bundle2的類時,它們在內部嘗試使用Class.forName()加載類。難道是在加載時,Class.forName()仍然使用第一個bundle中的classloader。 – user451445

+0

嗯林不知道,你張貼的清單,是捆綁1或2?你可以發佈兩個清單嗎? – cowls

回答

3

看來,如果你有一個org.compass.core.util.ClassUtils,它做了的Class.forName(),其級聯問題。

如果ClassUtils在bundle 2中,並且沒有給出明確的類加載器使用,它將默認爲bundle classloader。 bundleclassloader只能實例化bundle2可見的類(在整個類圖中)。

它很可能是它試圖加載的設置可能是bundle1中指定的類,這是不可見的。

解決方案是當涉及動態加載類或查看類加載器合作機制時,將類加載器從bundle1傳遞到bundle2。有一箇舊的article這可能解釋這一點更清晰。

相關問題