使用cmd的applet中的NoClassDefFoundError

时间:2014-12-29 13:31:49

标签: java jar cmd base64 japplet

我正在尝试使用cmd运行applet。我有两个jar文件,当我编译程序时,我使用了命令:

javac -g -cp jar1.jar;jar2.jar MainClass.java 

然后我使用了命令:

appletviewer MainClass.html

在浏览器中运行applet。 当我按下applet中包含的按钮时,我收到以下错误:

Exception in thread "AWT-EventQueue-1" java.lang.NoClassDefFoundError: org/apach
e/commons/codec/binary/Base64
at MainClass.SearchApi(MainClass.java:279)
at MainClass$ButtonHandler.keyPressed(MainClass.java:172)
at java.awt.Component.processKeyEvent(Component.java:6463)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2829)
at java.awt.Component.processEvent(Component.java:6282)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1895)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:762)
at   java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1027)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeybo
ardFocusManager.java:899)
...

知道如何解决问题吗?

1 个答案:

答案 0 :(得分:0)

运行appletviewer时需要相同的类路径,以及编译时使用的类路径。

appletviewer -J-classpath -Jjar1.jar;jar2.jar MainClass.html