Search code examples
javanetbeans-8apache-commons-math

How to fix java.lang.NoClassDefFoundError in Netbeans?


I'm developing a library (fpotencia) wich I use from a GUI program (fpotenciaui). The library uses the commons math library.

When I run the GUI program I get:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/complex/Complex
    at fpotencia.Circuit.<init>(Circuit.java:101)
    at gui.MainGUI.<init>(MainGUI.java:34)
    at fpotenciaui.FPotenciaUI.main(FPotenciaUI.java:53)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.complex.Complex
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 3 more
Java Result: 1

I have read in here that this is due to the presence of the library at design time but not at run time.

I have also read here that I need to include the library commons-logging.jar from here, which I have done for both the libary and the UI projects.

I would like to be able to include whatever I need from Netbeans since when I share the code with others I do not want them to have to do things like including libraries in the path. I am electrical engineer and I find very messy having to do such things "manually", besides, why is Netbeans for if I have to include libraries in the path from the command line?

So my question is, why does Netbeans not sort this problem out if I am clearly including the library in the project?

PS: maybe I'm misunderstanding the problem, if so, I'd appreciate some guidance to get this solved. Thanks.


Solution

  • Ok, so basically I found out that (at least in Netbeans) when you create a library that has dependencies, those dependencies have to be included in whatever other project that you want to use the library you've made.