Main Tutorials

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>

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
9 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Krisztian Szeles
3 years ago

Thank you!

SRIRAM
8 years ago

Yes,Its working for me.Thanks for you help.

Arvind Das
9 years ago

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);

KeepThinking
10 years ago

Thanks a lot!

Oleg
10 years ago

Thanks!

Shashi
11 years ago

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

Pasha
11 years ago

Thanks!

2Ch
13 years ago

Thx a lot!

Quân Chùa
10 years ago

great ! my work is done.