views:

128

answers:

3

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(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

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?

A: 

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.

meriton
I am using both struts2-core-2.2.1 and the freemarker-2.3.16 that it came bundled with in the struts2-blank-2.2.1.war file available in the struts2-2.2.1-all.zip distribution.
Brian Kessler
A: 

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
Chris
No logs in tmp0. There are logs directories in tmp1 and tmp2, but tmp2 is empty. I've appended the tmp1 log above.
Brian Kessler
+1  A: 

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

JoseK
I had an older version of freemarker in c:\devtool\java\tools which is on my classpath, but neither updating nor deleting this resolved the issue.
Brian Kessler
@Brian Kessler: there must be one more somewhere. did you restart the server after deleting it? dont update it, delete the dupes.
JoseK
Restarted the server (always do): doesn't help. Currently searching my drives for more freemarker*.jar files, but I'm not expecting to find any. Well, I did find some copies in my eclipse workspace, buried within the \.metadata\.plugins folders, but between these being created by eclipse during development and the path not even being on my PATH or CLASSPATH, I don't think these should be relevant.
Brian Kessler
Checked the link to Jarvana... don't have anything on that list other than a single instance of freemarker-2.3.16 itself sitting in D:\education\java\Events\WebContent\WEB-INF\lib (now, just the one copy of just the one version).
Brian Kessler
Okay then lets see if any intelligence in the full stacktrace logs - not the localhost_access_log but the localhost.log or catalina.log?
JoseK
Found two more copies of freemarker.jar files in my jre6 and glassfish3 directories. I don't believe these are on my path or classpath, but I renamed both copies to freemarker.jar.bak. Didn't fix the problem though.
Brian Kessler
Searching for localhost.log and catalina.log, but I haven't been able to find any such beasts. Where should I look for them? Do I need to install or configure anything to produce these, or should Tomcat 6.0 or Eclipse be producing these already?
Brian Kessler
these should be in the same folder as the localhost_access logs you posted above. are there any other logs in that folder or tmp0 or tmpX?
JoseK
@Brian Kessler: and one more - the freemarker.jar.bak in the jre lib, try by moving it out of there to desktop or D:\, not just renaming it.
JoseK
No logs other than the one above (actually, now not even the one above.) However moving freemarker.jar[.bak] out of the jre lib solved the problem! :-) Imagine I'll be writing another question someday asking how to fix my JRE. :-p
Brian Kessler
@Brian Kessler: i've had that problem once on weblogic, glad it worked
JoseK