java.lang.NoClassDefFoundError的问题解决!


一开始不知道什么情况,进入CMD命令行到JAR目录下直接

java -jar MyJar.jar

运行jar文件,出现以下错误:

D:\JAVA\MyProject>java -jar MyJar.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widge
ts/Composite
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.signatureDiagnostic(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Composite
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 6 more


修改默认的包名称为myProject,运行,错误又出现:


 java.lang.NoClassDefFoundError

直接添加声明myProject.toSWT s = new myProject.toSWT();

可以运行了。然后在导出时选择,Runnable JAR file



选择toSWT(2),第三项



成功运行!


你可能感兴趣的:(JAVA)