我正在尝试编译一个开源software。构建工作正常,并导致jar文件“five-server.jar”。当我尝试从cmd运行此文件时,我收到了这些错误。
C:\Users\vickey\code\five-server\dist\main>java -jar five-server.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/SWTError
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.SWTError
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)
Could not find the main class: org.devtcg.five.Main. Program will exit.
任何建议有什么问题?
答案 0 :(得分:5)
SWT Jar文件取决于平台。 见http://www.jarfinder.com/index.php/java/info/org.eclipse.swt.SWTError
e.g。在Windows上,一个合适的jar将是: org.eclipse.swt.win32.win32.x86_3.1.0.jar
或在Mac OS X上: SWT-MacOSX的-3.0m7.jar
等等。 如果添加此依赖项,可能会遇到调用各种后续问题,例如:不管你是不是 使用32位或64位库。
这些依赖性问题现在出现的次数太多了,这太糟糕了: - (
答案 1 :(得分:2)
您必须设置类路径,使其至少包含类org.eclipse.swt.SWTError 或包含它的罐子:
java -classpath path/to/jar/containing/org.eclipse.swt.SWTError -jar five-server.jar
您还应该在five-server.jar
答案 2 :(得分:0)
Following the @Wolfgang Fahl answer, you might download the references here:
Standard Widget Toolkit » 4.3 x86
Maven reference: https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86.4.3.swt/org.eclipse.swt.win32.win32.x86/4.3
Standard Widget Toolkit » 4.3 x64
Maven reference: https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86_64.4.3.swt/org.eclipse.swt.win32.win32.x86_64/4.3