java 在 WebLogic 中运行时 ClassNotFoundException (HqlToken)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2702266/
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
ClassNotFoundException (HqlToken) when running in WebLogic
提问by leedm777
I have a .war file for an application that normally runs fine in Jetty.
我有一个应用程序的 .war 文件,该应用程序通常在 Jetty 中运行良好。
I'm trying to port the application to run in WebLogic, but at startup I'm getting these exceptions:
我正在尝试移植应用程序以在 WebLogic 中运行,但在启动时出现以下异常:
ERROR:Foo - Error in named query: findBar
org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from Bar]
at org.hibernate.hql.ast.HqlLexer.panic(HqlLexer.java:80)
at antlr.CharScanner.setTokenObjectClass(CharScanner.java:340)
at org.hibernate.hql.ast.HqlLexer.setTokenObjectClass(HqlLexer.java:54)
at antlr.CharScanner.<init>(CharScanner.java:51)
at antlr.CharScanner.<init>(CharScanner.java:60)
at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:56)
at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:53)
at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:50)
...
What's the best way to fix this?
解决此问题的最佳方法是什么?
I'm using Hibernate 3.3.1.GA and WebLogic 10.3.2.0.
我正在使用 Hibernate 3.3.1.GA 和 WebLogic 10.3.2.0。
回答by Pascal Thivent
WebLogic has its own version of ANTLR and this causes the problem you're facing. One way to solve it with a web application is to set the prefer-web-inf-classeselement in weblogic.xmlto true.
WebLogic 有自己的 ANTLR 版本,这会导致您面临的问题。使用 Web 应用程序解决此问题的一种方法是将prefer-web-inf-classes元素设置weblogic.xml为true.
<weblogic-web-app>
....
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
....
</weblogic-web-app>
The weblogic.xmlgoes in WEB-INF.
该weblogic.xml进去WEB-INF。
回答by Alexander Trofimov
In my opinion the best solution for war:
Create file webapp\WEB-INF\weblogic.xmland put the text
我认为最好的解决方案是war:创建文件webapp\WEB-INF\weblogic.xml并放置文本
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<prefer-application-packages>
<package-name>antlr.*</package-name>
</prefer-application-packages>
</container-descriptor>
</weblogic-web-app>
回答by shane lee
If you have an EAR project like myself then you need to add this element to weblogic ear deployment descriptor [weblogic-application.xml]
如果您有一个像我这样的 EAR 项目,那么您需要将此元素添加到 weblogic ear 部署描述符 [ weblogic-application.xml]
<wls:prefer-application-packages>
<wls:package-name>antlr.*</wls:package-name>
</wls:prefer-application-packages>
回答by Karthik N G
I wanted to deploy WAR file on weblogic 11g (Weblogic Server 10.3.5). Normally, in a web application one will have web.xml. In order to make Weblogic pick up the classes mentioned in web.xml, we need to include one file in WEB-INF/weblogic.xml. Below is the code.
我想在 weblogic 11g (Weblogic Server 10.3.5) 上部署 WAR 文件。通常,在 Web 应用程序中,会有 web.xml。为了让Weblogic 选取web.xml 中提到的类,我们需要在WEB-INF/weblogic.xml 中包含一个文件。下面是代码。
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<context-root>ProjectName</context-root>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
This solved the issue for me and I was able to deploy the WAR on weblogic. Please enable web archive option from weblogic console.
这为我解决了这个问题,我能够在 weblogic 上部署 WAR。请从 weblogic 控制台启用 web 存档选项。
回答by Ed Griebel
I had an EAR, so I had to add a file META-INF/weblogic-application.xml
我有一个 EAR,所以我不得不添加一个文件 META-INF/weblogic-application.xml
The file itself was very simple, this is for Oracle WebLogic 11g, a.k.a. WebLogic Server 10.3.x:
该文件本身非常简单,适用于 Oracle WebLogic 11g,又名 WebLogic Server 10.3.x:
<? xml version="1.0" ?>
<weblogic-application>
<prefer-application-packages>
<package-name>antlr.*</package-name>
</prefer-application-packages>
</weblogic-application>
回答by mwhs
For those of you who tried the aforementioned approach to declare the antlrnamespace as "prefer-application-packages" in the weblogic-application.xmldescriptor and who still have the same problem, you may try to override the classpath of the weblogic-domain in the start script with the libraries of your project directly:
对于那些尝试上述方法antlr在weblogic-application.xml描述符中将命名空间声明为“prefer-application-packages”并且仍然遇到相同问题的人,您可以尝试使用以下命令覆盖启动脚本中的 weblogic-domain 的类路径直接使用您的项目库:
To do so execute the following steps:
为此,请执行以下步骤:
1.) Find the file bin/startWeblogic.[sh|cmd]in your Weblogic domain home
1.)bin/startWeblogic.[sh|cmd]在您的 Weblogic 域主页中找到该文件
2.) find the line which says set SAVE_CLASSPATH=
2.) 找到说的那一行 set SAVE_CLASSPATH=
3.) Replace with this (on windows, adapt accordingly for mac/*nix)
3.) 用这个替换(在 Windows 上,相应地适应 mac/*nix)
set CLASSPATH=C:\SomeProject\WebContent\WEB-INF\lib\*;%SAVE_CLASSPATH%
rem set CLASSPATH=%SAVE_CLASSPATH%
set SAVE_CLASSPATH=
4.) Save, (re-)start your weblogic domain and cross fingers.
4.) 保存,(重新)启动您的 weblogic 域并交叉手指。
Nota bene: this is probably not a good idea if your domain is home to more than one deployed artefact. Also it might in some cases be adivsable to only pick the relevant jar files from your WEB-INF/lib folder. Of course if you use maven, you will need to host these libraries somewhere else.
注意:如果您的域包含多个已部署的人工制品,这可能不是一个好主意。此外,在某些情况下,可以只从 WEB-INF/lib 文件夹中选择相关的 jar 文件。当然,如果您使用 maven,您将需要在其他地方托管这些库。
This solution also works with the Weblogic Server started from within the eclipse Servers view, since the Oracle Weblogic adapter uses the command-line script to start the server.
此解决方案也适用于从 eclipse Servers 视图中启动的 Weblogic Server,因为 Oracle Weblogic 适配器使用命令行脚本来启动服务器。

