简体   繁体   English

eclipse导出jar java.lang.NoClassDefFoundError问题

[英]eclipse export jar java.lang.NoClassDefFoundError problem

When compile and run using eclipse there is no problem , but when I exported as jar with these setting , i got Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: gnu/io/SerialPortEventListener . 使用eclipse进行编译和运行时没有问题,但是当使用这些设置将其导出为jar时, Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: gnu/io/SerialPortEventListenerException in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: gnu/io/SerialPortEventListener

The jar exporter didn't export my extended jar library? jar导出器没有导出我的扩展jar库?

替代文字替代文字

This sentence from the Exceptions JavaDoc helps to understand what went wrong: Exceptions JavaDoc中的这句话有助于理解出了什么问题:

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found. 当前正在编译的类在编译时就存在搜索到的类定义,但是无法再找到该定义。

You've build the application on eclipse with no errors. 您已经在eclipse上构建了应用程序而没有任何错误。 So the classpath definition inside eclipse was good enough to compile all classes. 所以 Eclipse的类路径定义是不够好,编译所有类。

Now you export it, run it out of eclipse and encounter that error. 现在,您导出,跑出来日食和遇到错误。 The exported application does not use the eclipse projects classpath definition any more. 导出的应用程序不再使用eclipse项目的classpath定义。 And the currrent one does not include the library which contains the gnu.io.SerialPortEventListener . 当前版本不包括包含gnu.io.SerialPortEventListener的库。

The general solution is: fix the classpath problems for the exported jar. 通用解决方案是:修复导出的jar的类路径问题。

It could be a dependency issue, however, don't confuse ClassNotFoundException and NoClassDefFoundError . 这可能是一个依赖关系问题,但是请不要混淆ClassNotFoundException和NoClassDefFoundError Basically, it is saying there was a problem in the initialization of: gnu/io/SerialPortEventListener I would check that class for errors as a starting point. 基本上,这就是说初始化以下内容时存在问题: gnu/io/SerialPortEventListener作为起点,我将检查该类是否存在错误。

我已经通过使用fatjar解决了

You may also consider using the open source tool called WinRun4J . 您也可以考虑使用名为WinRun4J的开源工具。

This is available at http://winrun4j.sourceforge.net/ . 可从http://winrun4j.sourceforge.net/获得

I found this easy and effective to use . 我发现此方法简单易用。

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

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