Hibernate Error – Exception in thread “main” java.lang.NoClassDefFoundError: antlr/ANTLRException

This is caused by missing of the antlr library. It’s usually happened when you did invoke Hibernate’s query statement.


Exception in thread "main" java.lang.NoClassDefFoundError: antlr/ANTLRException
	at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:35)
	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:74)
	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
	at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
	at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
	at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
	at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
	at com.mkyong.common.App.main(App.java:23)
Caused by: java.lang.ClassNotFoundException: antlr.ANTLRException
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	... 8 more

Solution

You can download the library from Antlr official website

Or

Add the dependency in Maven’s pom.xml


        <dependency>
		<groupId>antlr</groupId>
		<artifactId>antlr</artifactId>
		<version>2.7.7</version>
	</dependency>

9 comments on “Hibernate Error – Exception in thread “main” java.lang.NoClassDefFoundError: antlr/ANTLRException

  1. I still have the same problem, i also upgraded to version 4.x.x. But it does not help. What could be the problem, any guesses ?

    My simple code is

    SessionFactory sf=HibernateUtil.getSessionFactory();
    Session session=sf.openSession();
    Query query = session.createQuery(“from customer where name = :username”);
    query.setParameter(“name”, username);
    //query.setParameter(“password”, password);
    List list = query.list();
    System.out.println(“customer is”+list);
    return (Customer)list.get(0);

    Reply
  2. Jar bundled in hibernate download, may be it is missed to be added into project library. it can downloaded from Hibernate download site

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *