Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java.lang.NoClassDefFoundError while using enum in a class

Tags:

java

enums

jetty

I am getting a weird java.lang.NoClassDefFoundError while deploying my code. No error when I compile it, but when I am deploying it using jetty, I get an error saying

org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name 'org.springframework.dao.annotation.
                                  PersistenceExceptionTranslationPostProcessor#0'
 defined in class path resource [applicationContext-dao.xml]:
  Initialization of bean failed;

nested exception is 
 org.springframework.beans.factory.BeanCreationException:
  Error creating bean with name 'sessionFactory'
  defined in class path resource [applicationContext-dao.xml]:
   Invocation of init method failed;

nested exception is
 java.lang.NoClassDefFoundError: com/core/model/Webhook$Event

The class looks like below

public class Webhook extends BaseObject implements Serializable {

    public enum Event {
        ORDER_CREATE,
        ORDER_UPDATE,
        ORDER_DELETE,
        TICKET_CREATE,
        TICKET_UPDATE,
        TICKET_DELETE,
        CUSTOMER_CREATE,
        CUSTOMER_UPDATE,
        CUSTOMER_DELETE,
        MENU_ITEM_UPDATE,
        CHECK_OFFER
    }

    private Event triggerEvent;

    public Event getTriggerEvent() {
        return triggerEvent;
    }

    public void setTriggerEvent(Event triggerEvent) {
        this.triggerEvent = triggerEvent;
    }

    public String getTriggerEventString() {
        return triggerEvent.toString();
    }

    public void setTriggerEventString(String triggerEvent) {
        this.triggerEvent = Event.valueOf(triggerEvent);
    }    
}

Any Idea whats happening? It doesn't even show what like the error is in.

like image 310
BrownTownCoder Avatar asked Oct 31 '22 13:10

BrownTownCoder


1 Answers

java.lang.NoClassDefFoundError - Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying to use the class again (and thus need to load it, since it failed last time), but we're not even going to try to load it, because we failed loading it earlier (and reasonably suspect that we would fail again). The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems. The point is, a NoClassDefFoundError is not necessarily a classpath problem.

When I deploy in Weblogic, I often had had NoClassDefFoundError due to Weblogic cache. May try to clean cache of jetty or rename Event enum to, for example, Event1 and try again?

like image 108
Slava Vedenin Avatar answered Nov 09 '22 12:11

Slava Vedenin