java为什么导出不了jar,为什么我得到“发生Java异常”在我将应用程序导出到Jar之后?...

Well, I exported my application into JAR with eclipse, but now whenever I try running it I get the: "A Java Exception has occurred". When I try to run it through command line it says:

C:\Users\Arturas>java -jar D:\Dropbox\EclipseWorkspace\Exports\Dantracio_skaiciu

oklis3.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.getMainMethod(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

C:\Users\Arturas>

Any solutions to this? I just hate java for this... It never works on desktops when you want it to... sorry I'm really stressed out from this, I'm overreacting...

Any ideas what could cause this? I doesn't work on other computers as well. Right now it's using Java 1.7. And the application runs perfectly on Eclipse.

解决方案

You need to get your dependencies. Looks like you are depending on swt, which is not part of the core java language. You'll need to get all the third party jars that you depend on and include them in your classpath. It runs perfectly on eclipse because eclipse takes care of setting up the classpath for you.

You can set the classpath in your manifest file as described in the documentation, or you could include a script to start your application that will use the -cp command when running the jar, or you can use something that will package everything into one monster jar like the solutions to this question.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值