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 the Author

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

Comments

Leave a Reply

avatar
newest oldest most voted
Oleg
Guest
Oleg

Thanks!

SRIRAM
Guest
SRIRAM

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

Arvind Das
Guest
Arvind Das

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
Guest
KeepThinking

Thanks a lot!

Shashi
Guest
Shashi

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

Pasha
Guest
Pasha

Thanks!

trackback
Hibernate Tutorials

[…] java.lang.NoClassDefFoundError: antlr/ANTLRException […]

2Ch
Guest
2Ch

Thx a lot!

Quân Chùa
Guest
Quân Chùa

great ! my work is done.