英文:
Eclipse external libraries
问题
以下是翻译好的内容:
我在使用Eclipse中的外部库时遇到了问题。每当我尝试启动程序时,都会抛出NoClassDefFound异常。显然我做错了什么。有人能重新为我解释一下如何将它们正确地包含到项目中吗?(是的,我已经在这方面做了很多研究,并且有人建议我使用Maven依赖,但我不想这样做。我还找到了一些与我的问题更相关的主题,但没有任何帮助。所以,如果有人能够解释具体应该做什么,我会非常感激。)
我正在使用最新版本的Eclipse和Java 8(通常是13,但那并没有解决我的错误)。它只在运行时抛出异常,因此在没有任何错误的情况下编译。
项目设置:http://prntscr.com/udsxts
清单文件:
Manifest-Version: 1.0
Main-Class: me.sxlver.consoleclient.Main
Class-Path: lib/java-json.jar lib/snakeyaml-1.26.jar
异常:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
at me.sxlver.consoleclient.Main.main(Main.java:20)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
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)
(我只是在创建一个JSONObject的实例)
Java Build Path:http://prntscr.com/udtgjn
英文:
I am currently experiencing issues whilst using external libraries in Eclipse. Whenever I am trying to launch my program it throws a NoClassDefFound exception. I am obviously doing something wrong. Could someone re-explain for me how to properly include them into your project? (Yes I have already done a lot of research on this and got recommended to use Maven dependencies which I don‘t want. Also I have found some threads that were more relevant to my issue but nothing helped. So yeah, I would really appreciate it if someone could explain what exactly to do.)
I am using the newest ver of eclipse together with java 8 (usually 13 but that did not fix my error). It only throws the exception on runtime so, it compiles without any errors.
Project setup: http://prntscr.com/udsxts
Manifest file:
Manifest-Version: 1.0
Main-Class: me.sxlver.consoleclient.Main
Class-Path: lib/java-json.jar lib/snakeyaml-1.26.jar
Exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
at me.sxlver.consoleclient.Main.main(Main.java:20)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
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)
(I am just creating an instance of JSONObject)
Java Build Path: <http://prntscr.com/udtgjn>
Libraries: <http://prntscr.com/udtqas>
答案1
得分: 0
我怀疑这可能是由于构建路径设置不正确造成的。我通常的做法是:
- 进入
Window
->Preferences
->Java
->Build Path
->User Library
->New Library
-> 添加jar
(你的lib
文件)。 - 右键点击你的项目 ->
Build Path
->Add Libraries
->Add User Libraries
->Done
。
英文:
I suspect this is due to the build path was setup incorrectly. What I normally do is:
- Go to
Window
->Preferences
->Java
->Build Path
->User Library
->New Library
-> Addjar
(yourlib
files). - Right click on your project ->
Build Path
->Add Libraries
->Add User Libraries
->Done
.
答案2
得分: 0
从Run菜单中,选择Run Configurations...
选择Dependencies选项卡,然后点击Add External JARs按钮
将会出现一个文件选择窗口。导航到相关的JAR文件位置并选择它。
英文:
From the Run menu, select Run Configurations...
Select Dependencies tab, then click on button Add External JARs
A file chooser window will appear. Navigate to the location of the relevant JAR and select it.
答案3
得分: 0
对我而言,有效的方法是:右键单击项目 -> 构建路径 -> 添加外部存档...
英文:
For me, what worked was: Right-click project -> Build Path -> Add External Archives...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论