I've created a library, let's call it MyLib
. This library, MyLib
, uses Google Guava
library, so I've Guava
's jar in the library folder that belongs to MyLib
.
Now I've created a new project where I'll use MyLib
. I've imported MyLib
to my project and when I run it I get this exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/eventbus/EventBus
at com.dwnz.mylib.<init>(SchoolBus.java:29)
at com.dwnz.mylib.getAsyncBusToMainThread(SchoolBus.java:61)
at view.MainFrame.<init>(MainFrame.java:91)
at view.MainFrame.newInstance(MainFrame.java:586)
at view.Main.main(Main.java:98)
Caused by: java.lang.ClassNotFoundException: com.google.common.eventbus.EventBus
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
Java Result: 1
I've googled and I found out that on run time JVM
can't load the class. If I add Google's Guava jar as library to my project I don't get this exception.
What I don't understand here is why can't JVM load Guava's class from MyLib
library if I've added Guava jar to MyLib
library?
How can I make it work this way? Otherwise I find it a bit pointless to create this library.
I'm using NetBeans
, if it makes any difference.