下面以eclipse-birt(報表)為例,介紹這種問題出現的原因以及解決之道:
分析比較好的見:http://developer.actuate.com/community/forum/index.php?/topic/9315-exception-javalangnosuchmethoderror/
1>現象:
I could run report as stand alone, but while I am trying to use report engine in weblogicI am getting following error.
java.lang.NoSuchMethodError: org.mozilla.javascript.ImporterTopLevel.initStandardObjects(Lorg/mozilla/javascript/Context;Z)V
root cause:
java.lang.NoSuchMethodError: org.mozilla.javascript.ImporterTopLevel.initStandardObjects(Lorg/mozilla/javascript/Context;Z)V
org.eclipse.birt.core.script.ScriptContext.(ScriptContext.java:80)
org.eclipse.birt.core.script.ScriptContext.(ScriptContext.java:67)
org.eclipse.birt.report.engine.executor.ExecutionContext.(ExecutionContext.java:295)
org.eclipse.birt.report.engine.api.impl.EngineTask.(EngineTask.java:137)
org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.(RunAndRenderTask.java:62)
org.eclipse.birt.report.engine.api.impl.ReportEngineHelper.createRunAndRenderTask(ReportEngineHelper.java:292)
org.eclipse.birt.report.engine.api.impl.ReportEngine.createRunAndRenderTask(ReportEngine.java:299)
com.teamcenter.project.birt.servlet.WebReport.doGet(WebReport.java:90)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.teamcenter.project.servlet.LoginTimerFilter.doFilter(LoginTimerFilter.java:74)
com.teamcenter.project.servlet.UTF8EncodingFilter.doFilter(UTF8EncodingFilter.java:50)
2>原因:
The problem is because the application server contains a older version of
Rhino's js.jar, while BIRT uses the latest version (1.6RC1). Because the js.jar
in the application server is loaded before the one in BIRT, the older version of class org.mozilla.javascript.Context is loaded. Since the older version of class org.mozilla.javascript.Context doesn't contain function initStandardObjects, a runtime java.lang.NoSuchMethodError happened.
To solve this kind of problem, the application server usually provides a
configuration to allow loading application's java classes before the app
server's.
3>解決:
the conflict was between Weblogic Application Server and BIRT library, in weblogic-application.xml we have added the following configuration which has resolved the issue. Configuration: <prefer-application-packages> <package-name>org.mozilla.*</package-name> </prefer-application-packages>
另外一篇比較好的文章: http://blog.csdn.net/hhb200766/article/details/7818142
在WEB-INF目錄下新建weblogic-application.xml文件
- <?xml version="1.0" ?>
- <weblogic-application>
- <prefer-application-packages>
- <package-name>antlr.*</package-name>
- </prefer-application-packages>
- </weblogic-application>
在weblogic.xml文件中插入一段配置:
- <container-descriptor>
- <prefer-web-inf-classes>true</prefer-web-inf-classes>
- </container-descriptor>
針對我自己的這個應用,也是參照上面的解決辦法的,具體如下:
config是我自己的一個web應用
在WEB-INF目錄下新建一個 application.xml 和 weblogic-application.xml文件,這兩個文件的內容是一模一樣的,估計只需要一個,至於哪一個可以再嘗試我這里就把兩個文件都保留着,這兩個文件的內容如下:
<?xml version="1.0"?> <weblogic-application> <prefer-application-packages> <package-name>org.mozilla.*</package-name> </prefer-application-packages> </weblogic-application>
緊接着在 weblogic.xml文件中修改一個配置,設置為true
<?xml version="1.0" encoding="UTF-8"?> <wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd"> <wls:context-root>/config</wls:context-root> <wls:charset-params> <wls:input-charset> <wls:resource-path>/*</wls:resource-path> <wls:java-charset-name>UTF-8</wls:java-charset-name> </wls:input-charset> </wls:charset-params> <wls:container-descriptor> <!-- yangw change false to true --> <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes> </wls:container-descriptor> </wls:weblogic-web-app>
最后重啟應用即可.