简体   繁体   English

Eclipse jar库[java.lang.NoClassDefFoundError]

[英]Eclipse jar library [java.lang.NoClassDefFoundError]

I'm trying to add some libraries to my project. 我正在尝试向我的项目中添加一些库。 When i debugging the application everything works perfect but when I compile the project and run it, i get: 当我调试应用程序时,一切工作都很好,但是当我编译项目并运行它时,我得到:

Exception in thread "main" java.lang.NoClassDefFoundError: de/javasoft/plaf/synt
hetica/SyntheticaSimple2DLookAndFeel
        at pkg_main.FRM_Main.main(FRM_Main.java:56)
Caused by: java.lang.ClassNotFoundException: de.javasoft.plaf.synthetica.Synthet
icaSimple2DLookAndFeel
        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)
        ... 1 more

Looks like the JVM can't get the library. 看起来JVM无法获取该库。 I tried the same in NetBeans and works perfectly so i think it's Eclipse problem. 我在NetBeans中尝试了同样的方法,并且运行良好,因此我认为这是Eclipse问题。

If anyone can help me please. 如果有人可以帮助我。 Thanks in advance! 提前致谢!

You're compiling/exporting your code successfully, but when you run it you're missing libraries from your classpath. 您正在成功编译/导出代码,但是在运行代码时,您的类路径中缺少库。

The difference between netbeans and eclipse is most likely that by default, netbeans includes all libraries in the jar when you export and eclipse does not. netbeans和eclipse之间的区别很可能是默认情况下,当您导出时,netbeans会包含jar中的所有库,而eclipse不会。 If you intend to package everything in a single jar, make sure that when you export from eclipse that you select all of the libraries on the first export screen. 如果要将所有内容打包在一个jar中,请确保从eclipse导出时选择第一个导出屏幕上的所有库。

If you'd prefer to export only your code(like if you expect to switch versions of a library without rebuilding your jar), you can continue exporting only your code, but when you run it you have to specify the libraries in the classpath 如果您只希望导出代码(例如,如果希望在不重建jar的情况下切换库的版本),则可以继续仅导出代码,但是在运行它时,必须在类路径中指定库

java -cp "yourJar.jar;lib/*" my.package.MainClass

在eclipse和Netbeans中检查您的类路径,您会发现差异,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM