java 我应该如何初始化类 freemarker.template.Configuration?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3799817/
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
How should I initialize class freemarker.template.Configuration?
提问by Brian Kessler
Attempting to follow this Java tutorial.
尝试遵循此 Java 教程。
About 63 pages in, you are instructed how to create a form ("New.jsp") to submit new events.
在大约 63 页中,将指导您如何创建表单(“New.jsp”)来提交新事件。
When I try to visit the page, I get the following error:
当我尝试访问该页面时,出现以下错误:
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
I found this log at D:\education\java.metadata.plugins\org.eclipse.wst.server.core\tmp1\logs\localhost_access_log.2010-09-26.txt
我在 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
I couldn't find any other logs.
我找不到任何其他日志。
Any ideas how to resolve this?
任何想法如何解决这个问题?
回答by JoseK
NoClassDefFound means that the class definition existed at compile time, but at runtime the definition is either not found or is not the same version.
NoClassDefFound 意味着类定义在编译时存在,但在运行时定义要么找不到,要么版本不同。
In your case I think it could be a problem of multiple versions of freemarker.template.Configuration
being found in the classpath. Ideally shoul only be in freemarker.jar but check if you've got one of these jarsin your server/lib and remove any duplicates
在您的情况下,我认为这可能是freemarker.template.Configuration
在类路径中找到多个版本的问题。理想情况下应该只在 freemarker.jar 中,但检查您的服务器/库中是否有这些 jar之一并删除任何重复项
If none of these, ensure no other versions of freemarker.jar other than in your war
如果没有这些,请确保除了您的War之外没有其他版本的 freemarker.jar
Updated solution as discovered in comments
在评论中发现的更新解决方案
Renaming duplicate freemarker.jar to .bak does not help, works when those moved out of the path/classpath
将重复的 freemarker.jar 重命名为 .bak 没有帮助,当那些移出路径/类路径时有效
回答by meriton
The javadoc for java.lang.NoClassDefErrorsays:
java.lang.NoClassDefError的 javadoc说:
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
如果 Java 虚拟机或 ClassLoader 实例尝试加载类的定义(作为正常方法调用的一部分或作为使用 new 表达式创建新实例的一部分)并且找不到类的定义,则抛出。
编译当前正在执行的类时,搜索到的类定义存在,但无法再找到该定义。
That is, struts attempts to delegate view rendering to freemarker, but freemarker is not in the classpath. Try to find out which version of freemarker your version of struts requires, and add that version of freemarker.jar to the classpath.
也就是说,struts 尝试将视图渲染委托给 freemarker,但 freemarker 不在类路径中。尝试找出您的 struts 版本需要哪个版本的 freemarker,然后将该版本的 freemarker.jar 添加到类路径中。
回答by Chris
Have a look in your logs and upload those. They should be in a folder like this:
查看您的日志并上传它们。它们应该在这样的文件夹中:
<<eclipse_workspace>>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\logs
回答by vijay
Just put the jar files in the WEB-INF/lib folder and thats all...
只需将 jar 文件放在 WEB-INF/lib 文件夹中,仅此而已...