-
Bug
-
Resolution: Done
-
Major
-
2.4.1.Final
-
None
I want to process a Freemaker template from a main class. The full code is here (https://github.com/agoncal/agoncal-sample-forge/blob/master/03-template/src/main/java/org/agoncal/sample/forge/template/RestEndpoint.java) and this is an abstract :
private void doIt() throws IOException { Furnace furnace = startFurnace(); try { ResourceFactory resourceFactory = furnace.getAddonRegistry().getServices(ResourceFactory.class).get(); TemplateProcessorFactory factory = furnace.getAddonRegistry().getServices(TemplateProcessorFactory.class).get(); Resource<URL> templateResource = resourceFactory.create(getClass().getResource("RestEndpoint.jv")); Template template = new FreemarkerTemplate(templateResource); // Mark this resource as a Freemarker template TemplateProcessor processor = factory.fromTemplate(template); Map<String, Object> params = new HashMap<String, Object>(); //Could be a POJO also. params.put("name", "JBoss Forge"); String output = processor.process(params); // should return "Hello JBoss Forge". System.out.println(output); } finally { furnace.stop(); } }
But I get the following error :
Exception in thread "main" org.jboss.forge.furnace.exception.ContainerException: Failed to create proxy for type [class org.jboss.forge.addon.templates.freemarker.FreemarkerTemplate] at org.jboss.forge.furnace.proxy.ClassLoaderAdapterCallback.enhance(ClassLoaderAdapterCallback.java:827) at org.jboss.forge.furnace.proxy.ClassLoaderAdapterCallback.enhance(ClassLoaderAdapterCallback.java:687) at org.jboss.forge.furnace.proxy.ClassLoaderAdapterCallback.enhanceSingleParameterValue(ClassLoaderAdapterCallback.java:617) at org.jboss.forge.furnace.proxy.ClassLoaderAdapterCallback.enhanceParameterValues(ClassLoaderAdapterCallback.java:489) at org.jboss.forge.furnace.proxy.ClassLoaderAdapterCallback.access$100(ClassLoaderAdapterCallback.java:34) at org.jboss.forge.furnace.proxy.ClassLoaderAdapterCallback$1.call(ClassLoaderAdapterCallback.java:92) at org.jboss.forge.furnace.util.ClassLoaders.executeIn(ClassLoaders.java:34) at org.jboss.forge.furnace.proxy.ClassLoaderAdapterCallback.invoke(ClassLoaderAdapterCallback.java:71) at org.jboss.forge.addon.templates.TemplateProcessorFactory_$$_javassist_381849cc-8aad-4339-adb9-66683e1ebbde.fromTemplate(TemplateProcessorFactory_$$_javassist_381849cc-8aad-4339-adb9-66683e1ebbde.java) at org.agoncal.sample.forge.template.RestEndpoint.doIt(RestEndpoint.java:47) at org.agoncal.sample.forge.template.RestEndpoint.main(RestEndpoint.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) Caused by: java.lang.InstantiationException: org.jboss.forge.addon.templates.Template_$$_javassist_840b9c34-f23e-4d1e-8a3e-14ff4dfc9c4e at java.lang.Class.newInstance(Class.java:359) at org.jboss.forge.furnace.proxy.ClassLoaderAdapterCallback$2.call(ClassLoaderAdapterCallback.java:785) at org.jboss.forge.furnace.util.ClassLoaders.executeIn(ClassLoaders.java:34) at org.jboss.forge.furnace.proxy.ClassLoaderAdapterCallback.enhance(ClassLoaderAdapterCallback.java:707) ... 15 more