Freemarker sucks, dependency on javax.swing, Wouldn’t run on GAE

I would say freemarker sucks.
Yes it does. A template engine has dependency on javax.swing !!
Isnt that surprising?

Today, I was trying to deploy a Stripe/Freemarker hello world app on GAE and I got following.


java.lang.NoClassDefFoundError: javax.swing.tree.TreeNode is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
at freemarker.core.TextBlock.isIgnorable(TextBlock.java:375)
at freemarker.core.TemplateElement.postParseCleanup(TemplateElement.java:240)
at freemarker.core.MixedContent.postParseCleanup(MixedContent.java:76)
at freemarker.core.FMParser.Root(FMParser.java:2961)
at freemarker.template.Template.(Template.java:149)
at freemarker.cache.TemplateCache.loadTemplate(TemplateCache.java:448)
at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:361)
at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:235)
at freemarker.template.Configuration.getTemplate(Configuration.java:487)
at freemarker.core.Environment.getTemplateForInclusion(Environment.java:1465)
at freemarker.core.Include.accept(Include.java:157)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.process(Environment.java:190)
at freemarker.template.Template.process(Template.java:237)
at freemarker.ext.servlet.FreemarkerServlet.process(FreemarkerServlet.java:452)
at freemarker.ext.servlet.FreemarkerServlet.doGet(FreemarkerServlet.java:391)
.........
........

Yes, you can not use freemarker on GAE, at least not without hacking it.

I found a patch here, seems that it would solve above exception.

http://groups.google.com/group/google-appengine-java/browse_thread/thread/dd84e44f604498c4

Who knows that it wouldn’t have dependency on more classes. we can just hope for good.

updates
Nope, above solution isn’t going to work all the time.
I had a quick look at the code, I think that the culprit is here.


abstract public class TemplateElement extends TemplateObject implements TreeNode

From the code, it seems that TemplateElement implements TreeNode
Just because it needs contract similar to TreeNode but it does not have any thing to do with swing API. (You already knew that)
Instead of implementing TreeNode, author could have created a new interface which exposes similar contract.

Do we implement any interface which exposes similar contract that we need? Context matters. EJB spec has some interface with methods that a servlet want doesn’t mean it can be implemented by a servlet.

Hope, devs would fix it in next release.
The issue is discussed in mailing list here http://n4.nabble.com/Dependeny-on-javax-swing-td978818.html

At the end, I would like to say, I like freemarker and that’s why I wrote even a hello world stripe application in freemarker.

Update 26/03/2010

Friends at freemarker has released a Freemarker GAE prerelease which can be downloaded here. It should work on GAE.  Any one interested in running freemarker on GAE should try it and report issues if any.

see  freemarker on GAE too.

update 28/04/2010

No, still freemarker-gae-pre2 will not work on GAE, I have tested it on GAE 1.3.2.  You will get one or both of the following exceptions

java.lang.VerifyError: (class: freemarker/ext/jsp/FreeMarkerJspApplicationContext, method: signature: ()V) Incompatible argument to function

OR

java.lang.NoClassDefFoundError: Could not initialize class freemarker.ext.jsp.PageContextFactory

See this thread and this thread . The issue has been reported to GAE team here vote for it.

Waiting for the freemarker or GAE team to come up with explanation/solution.

Advertisements