JavaFX:Exception => java.lang.NoClassDefFoundError

时间:2016-01-06 02:49:51

标签: java exception shared-libraries pdfbox

我是构建和部署java应用程序的新手 我开发了一个应该创建pdf文档的应用程序。为此,我使用apache中的 pdfbox-library 。为了构建应用程序,我使用 ant。

如果我在我的IDE(Luna 4.4)上运行该应用程序没有错误。但是在构建它并在我的电脑或其他电脑上运行 .jar 后,我得到以下异常:

  

线程中的异常" JavaFX应用程序线程" java.lang.NoClassDefFoundError:org / apache / pdfbox / encoding / EncodingManager           at helper.MyHelper.getSpecialCharacter(未知来源)           at helper.MyHelper.formatString(未知来源)           在controller.InvoiceC.fillView(未知来源)           在controller.InvoiceC $ MyTabListener.changed(未知来源)           在controller.InvoiceC $ MyTabListener.changed(未知来源)           at com.sun.javafx.binding.ExpressionHelper $ Generic.fireValueChangedEvent(ExpressionHelper.java:361)           at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)           在javafx.beans.property.ReadOnlyObjectWrapper $ ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyO bjectWrapper.java:176)           在javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:142)           在javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)           在javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)           在javafx.scene.control.SelectionModel.setSelectedItem(SelectionModel.java:102)           在javafx.scene.control.TabPane $ TabPaneSelectionModel.select(TabPane.java:717)           在javafx.scene.control.TabPane $ TabPaneSelectionModel.select(TabPane.java:735)           在javafx.scene.control.TabPane $ TabPaneSelectionModel.select(TabPane.java:656)           at com.sun.javafx.scene.control.behavior.TabPaneBehavior.selectTab(TabPaneBehavior.java:122)           at com.sun.javafx.scene.control.skin.TabPaneSkin $ TabHeaderSkin $ 5.handle(TabPaneSkin.java:1332)           at com.sun.javafx.scene.control.skin.TabPaneSkin $ TabHeaderSkin $ 5.handle(TabPaneSkin.java:1317)           at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)           at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)           at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)           at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.jav a:59)           at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)           at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)           at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)           at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)           at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)           at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)           at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)           at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)           at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)           at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)           在com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)           在com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)           在javafx.event.Event.fireEvent(Event.java:198)           在javafx.scene.Scene $ MouseHandler.process(Scene.java:3757)           在javafx.scene.Scene $ MouseHandler.access $ 1500(Scene.java:3485)           在javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)           在javafx.scene.Scene $ ScenePeerListener.mouseEvent(Scene.java:2494)           at com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(GlassViewEventHandler .java:352)           at com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(GlassViewEventHandler .java:275)           at java.security.AccessController.doPrivileged(Native Method)           at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda $ handleMouseEvent $ 355(GlassViewEventHandle r.java:388)           at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)           at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)           在com.sun.glass.ui.View.handleMouseEvent(View.java:555)           在com.sun.glass.ui.View.notifyMouse(View.java:937)           at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)           at com.sun.glass.ui.win.WinApplication.lambda $ null $ 149(WinApplication.java:191)           在java.lang.Thread.run(Thread.java:745)   引起:java.lang.ClassNotFoundException:org.apache.pdfbox.encoding.EncodingManager           at java.net.URLClassLoader.findClass(URLClassLoader.java:381)           at java.lang.ClassLoader.loadClass(ClassLoader.java:424)           at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:331)           at java.lang.ClassLoader.loadClass(ClassLoader.java:357)           ......还有50个

guide之后,我将所有必需的库添加到我的项目中。

libs

在这里你可以看到代码,它负责异常:

public static String formatString(float value) {
DecimalFormat df = new DecimalFormat("###,##0.00");
String s = String.valueOf(df.format(value));

try {
       s+= " " +getSpecialCharacter();
            switch(s.length()) {
                case 5: s = "         " +s; 
                    break;
                case 6: s = "       " +s;
                    break;
                case 7: s = "     " +s; 
                    break;
                case 8: s = "   " +s; 
                    break;

            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    return s;
}

public static String getSpecialCharacter() throws IOException {
    Encoding e = EncodingManager.INSTANCE.getEncoding(COSName.WIN_ANSI_ENCODING);
    return String.valueOf(Character.toChars(e.getCode("Euro")));
}

我真的很困惑,我希望有人会帮助我!!

1 个答案:

答案 0 :(得分:0)

@Tilman Hausherr帮助我解决了我的问题 我通过以下步骤解决了我的问题:

  1. 将pdfbox-app.1.8.10添加到我的项目
  2. 在我添加的罐子
  3. 的位置上运行我的建筑罐子