xstream noclassdeffound错误,具体取决于运行时

nfg76nw0  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(393)

我被xstream的问题困住了。我有两个基于osgi的rcp应用程序。它们使用xstream在xml文件中读写特定的类。当我运行程序并触发相关代码时,我得到:

com.thoughtworks.xstream.mapper.CannotResolveClassException: at.jku.mevss.memodel.internal.meta.ImplMevolMetaModel
        at at.jku.mevss.memodel.internal.persistence.MEMetaModelXStreamPersistor.loadUncompressedStream(MEMetaModelXStreamPersistor.java:56)
        at at.jku.mevss.memodel.internal.persistence.MEMetaModelXStreamPersistor.open(MEMetaModelXStreamPersistor.java:44)
        at at.jku.mevss.memodel.internal.persistence.MEMetaModelXStreamPersistor.open(MEMetaModelXStreamPersistor.java:1)
        at at.jku.mevss.util.persistence.AbstractModelPersistenceProvider.getModel(AbstractModelPersistenceProvider.java:111)
        at at.jku.mevss.util.persistence.AbstractModelPersistenceProvider.getModel(AbstractModelPersistenceProvider.java:70)
        at at.jku.mevss.eventdistributor.server.metamodel.MetaModelServiceInstance.fromFile(MetaModelServiceInstance.java:100)
        at at.jku.mevss.eventdistributor.server.metamodel.MetaModelServiceInstance.fromFile(MetaModelServiceInstance.java:1)
        at at.jku.mevss.eventdistributor.service.core.service.AbstractFileTransmitServiceInstance.reloadItems(AbstractFileTransmitServiceInstance.java:95)
        at at.jku.mevss.eventdistributor.service.core.service.AbstractFileTransmitServiceInstance.notifyFileChange(AbstractFileTransmitServiceInstance.java:61)
        at at.jku.mevss.eventdistributor.service.core.util.WatchServiceRunner$NotifyChangeTask.run(WatchServiceRunner.java:107)
        at java.util.TimerThread.mainLoop(Unknown Source)
        at java.util.TimerThread.run(Unknown Source)
Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: at.jku.mevss.memodel.internal.meta.ImplMevolMetaModel
        at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:81)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
        at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
        at com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:88)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
        at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:79)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
        at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:74)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
        at com.thoughtworks.xstream.mapper.SecurityMapper.realClass(SecurityMapper.java:71)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:125)
        at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:47)
        at com.thoughtworks.xstream.core.util.HierarchicalStreams.readClassType(HierarchicalStreams.java:29)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:133)
        at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1404)
        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1383)
        at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1268)
        at at.jku.mevss.memodel.internal.persistence.MEMetaModelXStreamPersistor.loadUncompressedStream(MEMetaModelXStreamPersistor.java:53)
        ... 11 more

com.thoughtworks.xstream.mapper.CannotResolveClassException: at.jku.mevss.memodel.internal.meta.ImplMevolMetaModel
        at at.jku.mevss.memodel.internal.persistence.MEMetaModelXStreamPersistor.loadUncompressedStream(MEMetaModelXStreamPersistor.java:56)
        at at.jku.mevss.memodel.internal.persistence.MEMetaModelXStreamPersistor.open(MEMetaModelXStreamPersistor.java:44)
        at at.jku.mevss.memodel.internal.persistence.MEMetaModelXStreamPersistor.open(MEMetaModelXStreamPersistor.java:1)
        at at.jku.mevss.util.persistence.AbstractModelPersistenceProvider.getModel(AbstractModelPersistenceProvider.java:111)
        at at.jku.mevss.idetools.metaconfeditor.metamodel.editor.ModelEditor.doLoadItem(ModelEditor.java:253)
        at at.jku.mevss.idetools.metaconfeditor.metamodel.editor.ModelEditor.doLoadItem(ModelEditor.java:1)
        at at.jku.mevss.idetools.launch.editor.AbstractRMMItemEditor.setInput(AbstractRMMItemEditor.java:83)
        at org.eclipse.ui.forms.editor.FormEditor.init(FormEditor.java:128)
        at org.eclipse.ui.internal.EditorManager.createSite(EditorManager.java:828)
        at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:647)
        at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:465)
        at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
        at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:315)
        at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
        at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
        at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
        at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
        at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1245)
        at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1198)
        at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1597)
        at org.eclipse.ui.internal.PartStack.add(PartStack.java:493)
        at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:103)
        at org.eclipse.ui.internal.PartStack.add(PartStack.java:479)
        at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:112)
        at org.eclipse.ui.internal.EditorSashContainer.addEditor(EditorSashContainer.java:63)
        at org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorAreaHelper.java:225)
        at org.eclipse.ui.internal.EditorAreaHelper.addEditor(EditorAreaHelper.java:213)
        at org.eclipse.ui.internal.EditorManager.createEditorTab(EditorManager.java:808)
        at org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor(EditorManager.java:707)
        at org.eclipse.ui.internal.EditorManager.openEditor(EditorManager.java:666)
        at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2946)
        at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2854)
        at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPage.java:2846)
        at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:2797)
        at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
        at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2793)
        at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2777)
        at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2760)
        at org.eclipse.ui.ide.IDE.openEditor(IDE.java:687)
        at at.jku.mevss.ui.ide.EditorUtil$1.run(EditorUtil.java:25)
        at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
        at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
        at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4144)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
        at org.eclipse.jface.operation.ModalContext$ModalContextThread.block(ModalContext.java:173)
        at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:388)
        at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
        at at.jku.mevss.ui.util.dialogs.AbstractUIRunnable.runRunnable(AbstractUIRunnable.java:116)
        at at.jku.mevss.idetools.metaconfeditor.handler.CreateNewMetamodelHandler.execute(CreateNewMetamodelHandler.java:13)
        at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
        at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
        at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
        at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
        at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:829)
        at org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:815)
        at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:805)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
        at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
        at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
        at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
        at at.jku.mevss.product.application.monitoringmanager.MonitoringManagerApplication.start(MonitoringManagerApplication.java:25)
        at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1438)

有问题的班级 at.jku.mevss.memodel.internal.meta.ImplMevolMetaModel 在执行序列化和反序列化的同一个包中。不过,它的 Package 不同。在ide中,两个应用程序都可以正常工作,而且不必为xstream设置特定的类加载器。我还尝试通过执行以下操作来更改xstream使用的类加载器:

xstream.setClassLoader(Thread.currentThread().getContextClassLoader());

对于为构建版本工作的两个应用程序之一,它能够从xml读取和生成对象,但另一个应用程序似乎有不同的contextclassloader,或者它的可加载类列表中没有有问题的类。
如何提供一个能够独立于osgi包在哪个应用程序中运行而加载给定类的类加载器?

igetnqfo

igetnqfo1#

通过将xstream的类加载器设置为 xstream.setClassLoader(getClass().getClassLoader()); . 这对我来说仍然有点神秘,因为我已经查找了xstream的源代码,并且根据默认xstream创建了一个复合类加载器类,该类应该始终包含 getClass().getClassLoader() 以及 Object.class.getClassLoader() . 看看这里的来源。最后,我通过手动正确设置类加载器,再次检查了它,这基本上只是一点运气。

相关问题