java – ClassNotFoundException:org. dom4j. DocumentException
I am trying to debug (F11 on eclipse) the Java GUI application I inherited, but when the application outside the eclipse ide runs normally (minus a small fix I need to apply), it generates the following exception (F11 or Ctrl F11) when starting from eclipse:
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
My initial search for this found that the Dom4j library may be missing, but added it to 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>
The problem was not solved
Do you know why I get this exception (only when starting from eclipse) and how to solve it?
Incidentally, saxson dependencies are added only because of dependencies that cannot be resolved at build time due to trying to use the latest Dom4j But since I was demoted to Dom4j 1.6 After 1, I can eliminate Saxon dependency, so POM The XML file now contains only:
<dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency> </dependencies>
Solution
I'll go to the eclipse "debug" view and get the actual commands eclipse uses to run the program
Edit – just to be clear, when I say "debug view", I mean
"Main Menu"->"Window"->"Show View"->"Debug"