正在尝试关注 this Java tutorial .
在第 63 页中,您被告知如何创建表单(“New.jsp”)以提交新事件。
当我尝试访问该页面时,出现以下错误:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Filter execution threw an exception
com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
root cause
java.lang.NoClassDefFoundError: Could not initialize class freemarker.template.Configuration
org.apache.struts2.views.freemarker.FreemarkerManager.createConfiguration(FreemarkerManager.java:294)
org.apache.struts2.views.freemarker.FreemarkerManager.init(FreemarkerManager.java:255)
org.apache.struts2.views.freemarker.FreemarkerManager.getConfiguration(FreemarkerManager.java:238)
org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:734)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:506)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.
Apache Tomcat/6.0.29
我在 D:\education\java.metadata.plugins\org.eclipse.wst.server.core\tmp1\logs\localhost_access_log.2010-09-26.txt 找到了这个日志
127.0.0.1 - - [26/Sep/2010:04:29:09 +0200] "GET / HTTP/1.1" 404 953
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:29:11 +0200] "GET /Events/ HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:29:11 +0200] "GET /favicon.ico HTTP/1.1" 404 986
127.0.0.1 - - [26/Sep/2010:04:56:53 +0200] "GET / HTTP/1.1" 404 953
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /Events/events/Listing.action HTTP/1.1" 200 963
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /Events/assets/styles.css HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /Events/assets/bg.jpg HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /Events/assets/alpha-b.png HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /Events/assets/alpha-w.png HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [26/Sep/2010:04:56:55 +0200] "GET /favicon.ico HTTP/1.1" 404 986
0:0:0:0:0:0:0:1 - - [26/Sep/2010:05:02:49 +0200] "GET /Events/ HTTP/1.1" 404 974
0:0:0:0:0:0:0:1 - - [26/Sep/2010:05:02:49 +0200] "GET /favicon.ico HTTP/1.1" 404 986
我找不到任何其他日志。
有什么解决办法吗?
最佳答案
NoClassDefFound 表示类定义在编译时存在,但在运行时定义未找到或版本不同。
在您的情况下,我认为这可能是在类路径中找到多个版本的 freemarker.template.Configuration
的问题。理想情况下应该只在 freemarker.jar 但 check if you've got one of these jars在您的服务器/库中并删除所有重复项
如果这些都不是,请确保除了你的 war 之外没有其他版本的 freemarker.jar
评论中发现的更新解决方案
将重复的 freemarker.jar 重命名为 .bak 没有帮助,当那些移出路径/类路径时有效
关于java - 我应该如何初始化类 freemarker.template.Configuration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3799817/