以下情况:
在工作中,我们有一个自己的插件,它扩展了一些JDT功能,并为我们自己的框架构建了一些辅助函数。到现在为止还挺好。
该插件包括以下课程:
public class MoxLogFactory extends org.apache.commons.logging.LogFactory {
...
}
(我遗漏了具体的实施,因为它真的很全面)
现在我将WindowBuilder-Plugin添加到我的eclipse安装中。我可以创建包含向导的新项目和类。但主要特征 - 编辑本人 - 不起作用。它出来了,WindowBuilder试图从我们的插件加载类“MoxLogFactory”!如果我打开编辑器,我附上了堆栈跟踪:
java.lang.ClassNotFoundException: org.dreamox.moxanos.log.MoxLogFactory
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.commons.logging.LogFactory.createFactory(LogFactory.java:1261)
at org.apache.commons.logging.LogFactory$2.run(LogFactory.java:1065)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.commons.logging.LogFactory.newFactory(LogFactory.java:1062)
at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:497)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:704)
at org.apache.commons.digester.Digester.<init>(Digester.java:340)
at org.eclipse.wb.internal.core.model.description.helpers.ComponentDescriptionHelper.getDescription0(ComponentDescriptionHelper.java:375)
at org.eclipse.wb.internal.core.model.description.helpers.ComponentDescriptionHelper.getDescription0(ComponentDescriptionHelper.java:289)
at org.eclipse.wb.internal.core.model.description.helpers.ComponentDescriptionHelper.getDescription(ComponentDescriptionHelper.java:258)
at org.eclipse.wb.internal.core.model.JavaInfoUtils.createJavaInfo(JavaInfoUtils.java:386)
at org.eclipse.wb.internal.rcp.parser.ParseFactory.getRootContext(ParseFactory.java:184)
at org.eclipse.wb.internal.core.parser.JavaInfoParser.prepareParseContext(JavaInfoParser.java:1185)
at org.eclipse.wb.internal.core.parser.JavaInfoParser.parse(JavaInfoParser.java:244)
at org.eclipse.wb.internal.core.parser.JavaInfoParser.access$9(JavaInfoParser.java:240)
at org.eclipse.wb.internal.core.parser.JavaInfoParser$1.runObject(JavaInfoParser.java:153)
at org.eclipse.wb.internal.core.parser.JavaInfoParser$1.runObject(JavaInfoParser.java:1)
at org.eclipse.wb.internal.core.utils.execution.ExecutionUtils.runDesignTime(ExecutionUtils.java:153)
at org.eclipse.wb.internal.core.parser.JavaInfoParser.parse(JavaInfoParser.java:151)
at org.eclipse.wb.internal.core.editor.DesignPage.internal_refreshGEF(DesignPage.java:522)
at org.eclipse.wb.internal.core.editor.DesignPage.access$9(DesignPage.java:510)
at org.eclipse.wb.internal.core.editor.DesignPage$8$1.run(DesignPage.java:437)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4683)
at org.eclipse.wb.internal.core.editor.DesignPage$8.run(DesignPage.java:434)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
at org.eclipse.wb.internal.core.editor.DesignPage.internal_refreshGEF_withProgress(DesignPage.java:453)
at org.eclipse.wb.internal.core.editor.DesignPage.internal_refreshGEF(DesignPage.java:403)
at org.eclipse.wb.internal.core.editor.UndoManager.refreshDesignerEditor(UndoManager.java:381)
at org.eclipse.wb.internal.core.editor.UndoManager.activate(UndoManager.java:90)
at org.eclipse.wb.internal.core.editor.DesignPage.handleActiveState_True(DesignPage.java:251)
at org.eclipse.wb.internal.core.editor.DesignPage.handleActiveState(DesignPage.java:229)
at org.eclipse.wb.internal.core.editor.multi.DefaultMultiMode.showPage(DefaultMultiMode.java:125)
at org.eclipse.wb.internal.core.editor.multi.DefaultMultiMode$1.widgetSelected(DefaultMultiMode.java:63)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
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.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:2746)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1433)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:257)
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:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:999)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:893)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:85)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:579)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:534)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
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:352)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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:624)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:579)
at org.eclipse.equinox.launcher.Main.run(Main.java:1433)
at org.eclipse.equinox.launcher.Main.main(Main.java:1409)
我们的插件不会导出任何内容,那么为什么WindowBuilder会尝试从中加载一个类?它在哪里获取加载此类的信息?如果我卸载我们的插件,WindowBuilder工作正常,但我需要两个插件才能有效工作。
我发现,在MoxLogFactory中,在一个静态方法中有一行
System.setProperty("org.apache.commons.logging.LogFactory","org.dreamox.moxanos.log.MoxLogFactory");
我认为每个插件都在沙箱中运行,所以这不是一个真正的问题,但是当我看到堆栈跟踪时,似乎这个系统属性是“eclipse中的全局”。 MoxLogFactory类也用在我们的应用程序服务器框架中,因此需要此代码 - 插件使用框架本身来工作。
我不知道如何解决这个问题,并会欣赏任何提示或想法。
答案 0 :(得分:2)
以下是一些选项:
删除JVM级别系统属性的静态初始化,并仅在需要时通过命令行选项替换它
在静态初始化程序中,例如通过向ClassLoader询问org.eclipse.equinox.launcher.Main
类来测试Eclipse执行上下文,如果是,则不要设置logfactory属性
答案 1 :(得分:0)
系统属性属于JVM,而不属于类加载器。通过将您的记录器设置为系统属性,可能会自动加载,您已告知整个系统使用它。当另一个插件加载并尝试初始化其日志记录(似乎也使用Apache Commons Logging)时,它会读取System属性,尝试加载其中找到的类,并立即失败,因为它无法看到您的插件。