java.lang.ClassNotFoundException: antlr.ANTLRException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23600044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 00:14:56  来源:igfitidea点击:

java.lang.ClassNotFoundException: antlr.ANTLRException

javaantlr

提问by king jia

I have a method to get first result of a table.

我有一种方法可以获取表格的第一个结果。

public T LoadFirstData()
{
    T object = null;
    try {
        startOperation();
        Query query = session.createQuery("from " + type.getName());
        object = (T) query.list().get(0);
    } 
    catch (HibernateException e) 
    {
        HandleException(e);
    } finally 
    {
        HibernateUtil.Close(session);
    }
    return object;
}

But, when I run the method, I have the exception

但是,当我运行该方法时,出现异常

Exception in thread "main" java.lang.NoClassDefFoundError: antlr/ANTLRException
    at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:58)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:98)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98)
    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1760)
    at DataAccess.WKS.Repositories.WksRepositoryBase.LoadAllData(WksRepositoryBase.java:193)
    at Run.main(Run.java:13)
Caused by: java.lang.ClassNotFoundException: antlr.ANTLRException
    at java.net.URLClassLoader.run(Unknown Source)
    at java.net.URLClassLoader.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 9 more

I have searched on the web for the solution, all I found was missing antlr jar. But I have already added the jar into my project.

我在网上搜索了解决方案,我发现的只是缺少 antlr jar。但是我已经将 jar 添加到我的项目中。

list of jars:

罐子清单:

ant-antlr.jar
antlr-4.2.2.jar
antlr-runtime-4.2.2.jar
asm-attrs.jar
asm.jar
cglib-2.2.jar
commons-collections-3.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
hibernate-3.1.jar
hibernate3-client.jar
hibernate3.jar
javassist.jar
jboss-client.jar
jta.jar
log4j-1.2.15.jar
ojdbc14-jdbc4.jar
ojdbc14.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar

Can I know what else I have missed?

我能知道我还错过了什么吗?

采纳答案by vkg

You have the wrong antlr in your project.

您的项目中有错误的 antlr。

The one you need is this. I hope it helps :)

你需要的是这个。我希望它有帮助:)

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

I also see that you are using a older version of hibernate. Latest one available is

我还看到您使用的是旧版本的休眠。最新可用的是

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.3.5.Final</version>
</dependency>

Download latest hibernate jars

下载最新的休眠 jars