5

我正在尝试调试(Eclipse 上的 F11)我继承的 java GUI 应用程序,但是当应用程序在 Eclipse IDE 之外运行良好(减去我需要应用的微小修复)时,从 Eclipse 启动时会产生以下异常(F11或 Ctrl+F11):

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
    at com.example.myapp.LoginWindow.buildHibernateConfig(LoginWindow.java:178)
    at com.example.myapp.LoginWindow.actionPerformed(LoginWindow.java:141)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
    at javax.swing.plaf.basic.BasicRootPaneUI$Actions.actionPerformed(BasicRootPaneUI.java:191)
    at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1639)
    at javax.swing.JComponent.processKeyBinding(JComponent.java:2859)
    at javax.swing.KeyboardManager.fireBinding(KeyboardManager.java:267)
    at javax.swing.KeyboardManager.fireKeyboardAction(KeyboardManager.java:216)
    at javax.swing.JComponent.processKeyBindingsForAllComponents(JComponent.java:2936)
    at javax.swing.JComponent.processKeyBindings(JComponent.java:2928)
    at javax.swing.JComponent.processKeyEvent(JComponent.java:2822)
    at java.awt.Component.processEvent(Component.java:6074)
    at java.awt.Container.processEvent(Container.java:2039)
    at java.awt.Component.dispatchEventImpl(Component.java:4660)
    at java.awt.Container.dispatchEventImpl(Container.java:2097)
    at java.awt.Component.dispatchEvent(Component.java:4488)
    at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1856)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:722)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1000)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:865)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:686)
    at java.awt.Component.dispatchEventImpl(Component.java:4532)
    at java.awt.Container.dispatchEventImpl(Container.java:2097)
    at java.awt.Window.dispatchEventImpl(Window.java:2489)
    at java.awt.Component.dispatchEvent(Component.java:4488)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:668)
    at java.awt.EventQueue.access$400(EventQueue.java:81)
    at java.awt.EventQueue$2.run(EventQueue.java:627)
    at java.awt.EventQueue$2.run(EventQueue.java:625)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:641)
    at java.awt.EventQueue$3.run(EventQueue.java:639)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:638)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
    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)
    ... 47 more

我对此的初步搜索发现可能缺少 dom4j 库,但将其添加到 pom.xml:

    <dependency>
        <groupId>net.sourceforge.saxon</groupId>
        <artifactId>saxon</artifactId>
        <version>9.1.0.8</version>
    </dependency>        
   <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>
    </dependencies>

没有解决问题。

知道为什么我会收到此异常(仅在从 Eclipse 启动时)以及如何解决此问题?

顺便说一句,saxson添加依赖项只是因为尝试使用最新的 dom4j在构建时导致无法解决的依赖项。但是由于我降级到dom4j 1.6.1我可以消除 saxon 依赖,所以 pom.xml 文件现在只包含:

   <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>
    </dependencies>
4

2 回答 2

2

兄弟,你需要导入所有的 jar 文件来运行你的程序。这些是运行项目所必需的

Poi-3.10-Final.jar

Poi-ooxml-3.10-Final.jar

Poi-ooxml-schemas-3.10.jar

xmlbeans-2.30.jar

于 2014-03-20T16:15:31.993 回答
1

我将转到 Eclipse“调试”视图并获取 Eclipse 用于运行您的程序的实际命令。您应该在程序启动后立即暂停程序,然后右键单击“调试”视图中的第二行,然后选择属性。您将看到一个名为“进程属性”的窗口,可以从中复制 Eclipse 生成的命令以运行您的程序。您可以将命令粘贴到终端中,然后查看 Java 如何解析类路径。通过添加 -verbose 参数查看实际加载了哪些 jar。

编辑 - 为了清楚起见,当我说“调试视图”时,我的意思是

"Main Menu"->"Window"->"Show View"->"Debug"
于 2013-03-17T13:20:04.990 回答