不能在bndtools osgi项目中反序列化XML



我对osgi和bndtools相当陌生,从bndtools教程开始

教程工作得很好,然后我试着玩我自己的测试项目,我实现了一个接口,在实现中,我试图使用org.simpleframework将XML文件反序列化为Java类。

我得到以下classnotfound异常。此外,我确实将包(所讨论的类是其中的一部分)作为我正在运行的包中的私有包的一部分包含在

中。

. lang。packagename ClassNotFoundException。名称在$1.run(未知来源)at$1.run(未知来源)atjava.security.AccessController。特权(本地方法)在findclass(未知来源java.lang.ClassLoader。loadClass(未知源)sun.misc.Launcher AppClassLoader美元。loadClass(未知源)java.lang.ClassLoader。loadClass(未知源)org.simpleframework.xml.strategy.Loader.load (Loader.java: 50)org.simpleframework.xml.strategy.TreeStrategy.readValue (TreeStrategy.java: 163)在org.simpleframework.xml.strategy.TreeStrategy.read (TreeStrategy.java: 102)org.simpleframework.xml.core.Source.getOverride (Source.java: 370)在org.simpleframework.xml.core.Factory.getConversion (Factory.java: 207)org.simpleframework.xml.core.Factory.getOverride (Factory.java: 139)在org.simpleframework.xml.core.ObjectFactory.getInstance (ObjectFactory.java: 63)org.simpleframework.xml.core.Composite.read (Composite.java: 141)在org.simpleframework.xml.core.Composite.readVariable (Composite.java: 687)在org.simpleframework.xml.core.Composite.readInstance (Composite.java: 635)在org.simpleframework.xml.core.Composite.readUnion (Composite.java: 610)在org.simpleframework.xml.core.Composite.readElement (Composite.java: 593)在org.simpleframework.xml.core.Composite.readElements (Composite.java: 506)在org.simpleframework.xml.core.Composite.readSection (Composite.java: 388)org.simpleframework.xml.core.Composite.read (Composite.java: 367)org.simpleframework.xml.core.Composite.read (Composite.java: 234)org.simpleframework.xml.core.Composite.read (Composite.java: 202)org.simpleframework.xml.core.Composite.read (Composite.java: 150)(Traverser.java:92org.simpleframework.xml.core.CompositeList.populate (CompositeList.java: 175)在org.simpleframework.xml.core.CompositeList.read (CompositeList.java: 148)在org.simpleframework.xml.core.Composite.readVariable (Composite.java: 682)在org.simpleframework.xml.core.Composite.readInstance (Composite.java: 635)在org.simpleframework.xml.core.Composite.readUnion (Composite.java: 610)在org.simpleframework.xml.core.Composite.readElement (Composite.java: 593)在org.simpleframework.xml.core.Composite.readElements (Composite.java: 506)在org.simpleframework.xml.core.Composite.readSection (Composite.java: 388)org.simpleframework.xml.core.Composite.read (Composite.java: 367)在org.simpleframework.xml.core.Composite.readDefault (Composite.java: 262)org.simpleframework.xml.core.Composite.read (Composite.java: 232)org.simpleframework.xml.core.Composite.read (Composite.java: 202)org.simpleframework.xml.core.Composite.read (Composite.java: 150)在org.simpleframework.xml.core.Composite.readVariable (Composite.java: 687)在org.simpleframework.xml.core.Composite.readInstance (Composite.java: 635)在org.simpleframework.xml.core.Composite.readUnion (Composite.java: 610)在org.simpleframework.xml.core.Composite.readElement (Composite.java: 593)在org.simpleframework.xml.core.Composite.readElements (Composite.java: 506)在org.simpleframework.xml.core.Composite.readSection (Composite.java: 388)org.simpleframework.xml.core.Composite.read (Composite.java: 367)在org.simpleframework.xml.core.Composite.readDefault (Composite.java: 262)org.simpleframework.xml.core.Composite.read (Composite.java: 232)org.simpleframework.xml.core.Composite.read (Composite.java: 202)org.simpleframework.xml.core.Composite.read (Composite.java: 150)(Traverser.java:92org.simpleframework.xml.core.CompositeList.populate (CompositeList.java: 175)在org.simpleframework.xml.core.CompositeList.read (CompositeList.java: 148)在org.simpleframework.xml.core.Composite.readVariable (Composite.java: 682)在org.simpleframework.xml.core.Composite.readInstance (Composite.java: 635)在org.simpleframework.xml.core.Composite.readUnion (Composite.java: 610)在org.simpleframework.xml.core.Composite.readElement (Composite.java: 593)在org.simpleframework.xml.core.Composite.readElements (Composite.java: 506)在org.simpleframework.xml.core.Composite.readSection (Composite.java: 388)org.simpleframework.xml.core.Composite.read (Composite.java: 367)在org.simpleframework.xml.core.Composite.readDefault (Composite.java: 262)org.simpleframework.xml.core.Composite.read (Composite.java: 232)org.simpleframework.xml.core.Composite.read (Composite.java: 202)org.simpleframework.xml.core.Composite.read (Composite.java: 150)(Traverser.java:92org.simpleframework.xml.core.Persister.read (Persister.java: 632)org.simpleframework.xml.core.Persister.read (Persister.java: 613)org.simpleframework.xml.core.Persister.read (Persister.java: 591)org.simpleframework.xml.core.Persister.read (Persister.java: 550)org.simpleframework.xml.core.Persister.read (Persister.java: 528)org.simpleframework.xml.core.Persister.read (Persister.java: 433)com.mlsm.implementation.MLSMImpl.parseMLSM (MLSMImpl.java: 150)com.mlsm.implementation.MLSMImpl.executeInternal (MLSMImpl.java: 84)com.mlsm.implementation.MLSMImpl.parseAndExecute (MLSMImpl.java: 182)MLSMImpl.java:65sun.reflect.NativeMethodAccessorImpl。invoke0(本机方法)atsun.reflect.NativeMethodAccessorImpl。调用(未知源)atsun.reflect.DelegatingMethodAccessorImpl。调用(未知源)atjava.lang.reflect.Method。调用(未知源)atorg.apache.felix.dependencymanager.ServiceImpl.invoke (ServiceImpl.java: 484)在org.apache.felix.dependencymanager.ServiceImpl.activateService (ServiceImpl.java: 441)在org.apache.felix.dependencymanager.ServiceImpl.access 000美元(ServiceImpl.java: 44)在org.apache.felix.dependencymanager.ServiceImpl 3.美元运行(ServiceImpl.java: 125)在org.apache.felix.dependencymanager.SerialExecutor运行1.美元(SerialExecutor.java: 47)在org.apache.felix.dependencymanager.SerialExecutor.scheduleNext (SerialExecutor.java: 84)在org.apache.felix.dependencymanager.SerialExecutor.execute (SerialExecutor.java: 68)在org.apache.felix.dependencymanager.ServiceImpl.calculateStateChanges (ServiceImpl.java: 147)在org.apache.felix.dependencymanager.ServiceImpl.start (ServiceImpl.java: 257)在org.apache.felix.dependencymanager.DependencyManager.add (DependencyManager.java: 56)Activator.java:24org.apache.felix.dependencymanager.DependencyActivatorBase.start (DependencyActivatorBase.java: 76)在org.apache.felix.framework.util.SecureAction.startActivator (SecureAction.java: 645)org.apache.felix.framework.Felix.activateBundle (Felix.java: 2152)在org.apache.felix.framework.Felix.startBundle(Felix.java:2070org.apache.felix.framework.BundleImpl.start (BundleImpl.java: 976)aQute.launcher.Launcher.update (Launcher.java: 422)aQute.launcher.Launcher.activate (Launcher.java: 346)aQute.launcher.Launcher.run (Launcher.java: 235)aQute.launcher.Launcher.main (Launcher.java: 92)

service start()

public void start() {
Serializer serializer = new Persister();
File result = new File(filePath);
serializer.read(<ClassToSerializeTo>.class, result);
}

还有一点需要注意的是,这段代码在osgi框架之外工作得很好。如果更多的信息有助于调试这个问题,请告诉我。

我也读了这篇文章,但我仍然对手头的问题感到困惑。

编辑:我发现这只会发生在xml中有这样的元素

<TestElement class="PackageName.Classname">

任何想法?

感谢

我刚刚下载了simple-xml.jar的当前版本。Manifest现在显示OSGi属性。所以我的猜测是这个库在编写时没有考虑到OSGi。所以它可能有类加载问题。您应该在他们的邮件列表中询问他们是否应该在OSGi上工作。

如果它是框架中的问题,那么开发人员可能会修复它。也许你可以找到一个解决办法,但这可能不容易。

我通过在反序列化代码前面添加这两行来修复它

ClassLoader thisClassLoader = .getClassLoader();Thread.currentThread () .setContextClassLoader (thisClassLoader);

相关内容

  • 没有找到相关文章

最新更新