java -verion 和 javac -version 版本不一致
E:\temp\eclipseWorkSpace>java -jar TASTS.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Decorations
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Decorations
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)
Could not find the main class: MainForm. Program will exit.
E:\temp\eclipseWorkSpace>
E:\temp\eclipseWorkSpace>java -jar tasts.jar
Error: A JNI error has occurred, please check your installation and try again (java 版本不一致)
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Decorations
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Decorations
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
E:\temp\eclipseWorkSpace>
E:\temp\eclipseWorkSpace>java -jar tasts.jar
no main manifest attribute, in tasts.jar
在 cmd 下执行 java -jar xxx.jar 包名.类名
报错:
no main manifest attribute, in xxx.jar
产生原因:
一般情况下,java 打包成 jar 包需要在 MANIFEST.MF 中指定 Main-Class 项,以便运行 java -jar xxx.jar 时找到对应的主类。因为-jar的含义就是后面跟的jar包是有main class可独立运行,所以需要在打包成jar包时指定这个类;否则,需要在执行的时候手动指定。
解决方案:
在运行jar包时,使用 -cp / --classpath 来手动指定。
eg:java -cp xxx.jar com.fresher.xxx.类