ClassNotFoundException (HqlToken) when running in WebLogic

和自甴很熟 提交于 2019-12-21 04:14:34

问题


I have a .war file for an application that normally runs fine in Jetty.

I'm trying to port the application to run in WebLogic, but at startup I'm getting these exceptions:

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.


回答1:


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-classes element in weblogic.xml to true.

<weblogic-web-app>
  ....
  <container-descriptor>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
  </container-descriptor>
  ....
</weblogic-web-app>

The weblogic.xml goes in WEB-INF.




回答2:


In my opinion the best solution for war: Create file webapp\WEB-INF\weblogic.xml and put the text

<?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>



回答3:


If you have an EAR project like myself then you need to add this element to weblogic ear deployment descriptor [weblogic-application.xml]

<wls:prefer-application-packages>
        <wls:package-name>antlr.*</wls:package-name>
    </wls:prefer-application-packages>



回答4:


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.

    <?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.




回答5:


I had an EAR, so I had to add a file 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:

<? xml version="1.0" ?>
<weblogic-application>
  <prefer-application-packages>
    <package-name>antlr.*</package-name>
  </prefer-application-packages>
</weblogic-application>



回答6:


For those of you who tried the aforementioned approach to declare the antlr namespace as "prefer-application-packages" in the weblogic-application.xml descriptor 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:

To do so execute the following steps:

1.) Find the file bin/startWeblogic.[sh|cmd] in your Weblogic domain home

2.) find the line which says set SAVE_CLASSPATH=

3.) Replace with this (on windows, adapt accordingly for 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.

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.

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.



来源:https://stackoverflow.com/questions/2702266/classnotfoundexception-hqltoken-when-running-in-weblogic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!