我应该如何初始化类freemarker.template.Configuration?

时间:2010-09-26 21:05:03

标签: java spring tomcat struts2 freemarker

试图关注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

我找不到任何其他日志。

有任何想法如何解决这个问题?

4 个答案:

答案 0 :(得分:5)

NoClassDefFound表示类定义在编译时存在,但在运行时定义未找到或版本不同

在您的情况下,我认为可能是在类路径中找到freemarker.template.Configuration的多个版本的问题。理想情况下,只应在freemarker.jar中,但在服务器/ lib中check if you've got one of these jars并删除所有重复项

如果不是这些,请确保除了战争之外没有其他版本的freemarker.jar

更新了在评论中发现的解决方案

将重复的freemarker.jar重命名为.bak没有帮助,当那些移出路径/类路径时会起作用

答案 1 :(得分:0)

java.lang.NoClassDefError的javadoc说:

  

如果Java虚拟机或ClassLoader实例尝试,则抛出该异常   加载类的定义(如   正常方法调用的一部分或作为   使用创建新实例的一部分   新表达式)并没有定义   可以找到班级。

     

搜索的类定义   当前执行时存在   类被编译,但定义   再也找不到了。

也就是说,struts尝试将视图呈现委托给freemarker,但freemarker不在类路径中。尝试找出您的struts版本所需的freemarker版本,并将该版本的freemarker.jar添加到类路径中。

答案 2 :(得分:0)

查看您的日志并上传这些日志。它们应该在这样的文件夹中:

<<eclipse_workspace>>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\logs

答案 3 :(得分:-1)

只需将jar文件放在WEB-INF / lib文件夹中即可...