Search code examples
javavaadinnoclassdeffounderrorevent-bus

Vaadin: NoClassDefFoundError on SubscriberExceptionHandler?


Attempting to implement the same sort of Event and EventBus stuff that's in the Dashboard demo, I'm getting this error when I try to run the app:

=================================================================
Vaadin is running in DEBUG MODE.
Add productionMode=true to web.xml to disable debug features.
To show debug window, add ?debug to your application URL.
=================================================================
Aug 31, 2015 3:06:08 PM com.vaadin.server.DefaultErrorHandler doDefault
SEVERE: 
java.lang.NoClassDefFoundError: com/google/common/eventbus/SubscriberExceptionHandler
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2472)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:854)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1274)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
    at info.chrismcgee.sky.scheduling.SchedulingUI.<init>(SchedulingUI.java:48)

Line 48 in SchedulingUI.java is:

private final SchedulingEventBus schedulingEventbus = new SchedulingEventBus();

(I've mostly just replaced all the "Dashboard" references to "Scheduling" to conform with my web app.) Of course, it doesn't help that I am still trying to figure out the point of SchedulingEvent.java and SchedulingEventBus.java and how they work. (Still a newbie.)

EDIT 09/01/2015: For clarification about what I renamed, here is my SchedulingEventBus.java file:

package info.chrismcgee.sky.event;

import info.chrismcgee.sky.scheduling.SchedulingUI;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.SubscriberExceptionContext;
import com.google.common.eventbus.SubscriberExceptionHandler;

/**
 * A simple wrapper for Guava event bus. Defines static convenience methods for
 * relevant actions.
 * 
 * @author Marketing
 *
 */
public class SchedulingEventBus implements SubscriberExceptionHandler {

    private final EventBus eventBus = new EventBus(this);

    public static void post(final Object event) {
        SchedulingUI.getSchedulingEventbus().eventBus.post(event);
    }

    public static void register(final Object object) {
        SchedulingUI.getSchedulingEventbus().eventBus.register(object);
    }

    public static void unregister(final Object object) {
        SchedulingUI.getSchedulingEventbus().eventBus.unregister(object);
    }

    @Override
    public void handleException(final Throwable exception,
            final SubscriberExceptionContext context) {

        exception.printStackTrace();
    }

}

Solution

  • Add the following dependency to the ivy.xml file:

    <dependency org="com.google.guava" name="guava" rev="18.0"/>
    

    I was having the exact same problem trying to do the exact same thing. This cleared up the NoClassDefFoundError.