Attempting to follow this Java tutorial.
About 63 pages in, you are instructed how to create a form ("New.jsp") to submit new events.
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(StrutsPrepareAndExecut开发者_如何学JAVAeFilter.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
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?
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.
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 jars in your server/lib and remove any duplicates
If none of these, ensure no other versions of freemarker.jar other than in your war
Updated solution as discovered in comments
Renaming duplicate freemarker.jar to .bak does not help, works when those moved out of the path/classpath
The javadoc for java.lang.NoClassDefError says:
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.
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.
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
Just put the jar files in the WEB-INF/lib folder and thats all...
精彩评论