为什么我得到“发生Java异常”在我将应用程序导出到Jar之后? [英] Why do I get "A Java Exception has occurred" after I export my application to Jar?

查看:99
本文介绍了为什么我得到“发生Java异常”在我将应用程序导出到Jar之后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我用eclipse将我的应用程序导出到JAR中,但是现在每当我尝试运行它,我得到:发生Java异常。当我尝试通过命令行运行它说:

  C:\Users\Arturas> java -jar D: \Dropbox\EclipseWorkspace\Exports\Dantracio_skaiciu 
oklis3.jar
线程main中的异常java.lang.NoClassDefFoundError:org / eclipse / swt / widge
ts / Composite
在java.lang.Class.getDeclaredMethods0(本机方法)
在java.lang.Class.privateGetDeclaredMethods(未知来源)
在java.lang.Class.getMethod0(未知来源)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
引起通过:java.lang.ClassNotFoundException:org.eclipse.swt.widgets.Composite
在java.net.URLClassLoader $ 1.run(未知来源)
在java.net.URLClassLoader $ 1.run(未知来源)
在java.security.AccessController.doPrivileged(Native Meth od)
在java.net.URLClassLoader.findClass(未知来源)
在java.lang.ClassLoader.loadClass(未知源)
在sun.misc.Launcher $ AppClassLoader.loadClass(未知来源)
在java.lang.ClassLoader.loadClass(未知来源)
... 6更多

C:\Users\Arturas>

任何解决方案?我只是讨厌java这个...它从来没有工作在桌面上,当你想要...对不起,我真的很强调从这个,我反应过度...


$ b $任何想法可能会导致什么?我也不在其他电脑上工作。现在它使用Java 1.7。应用程序在Eclipse上完美运行。

解决方案

您需要获得依赖关系。看起来你依赖于swt,这不是核心java语言的一部分。您将需要获取所有依赖于您的第三方jar,并将它们包含在您的类路径中。它可以在eclipse上完美运行,因为eclipse负责为您设置类路径。



您可以按照文档,或者您可以包括一个脚本来启动应用程序,将使用 -cp 命令在运行jar时,或者您可以使用将所有内容打包成一个怪物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.

这篇关于为什么我得到“发生Java异常”在我将应用程序导出到Jar之后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆