简体   繁体   中英

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 .

The jar exporter didn't export my extended jar library?

替代文字替代文字

This sentence from the Exceptions JavaDoc helps to understand what went wrong:

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. So the classpath definition inside eclipse was good enough to compile all classes.

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. And the currrent one does not include the library which contains the gnu.io.SerialPortEventListener .

The general solution is: fix the classpath problems for the exported jar.

It could be a dependency issue, however, don't confuse ClassNotFoundException and 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.

我已经通过使用fatjar解决了

You may also consider using the open source tool called WinRun4J .

This is available at http://winrun4j.sourceforge.net/ .

I found this easy and effective to use .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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