Re: RhinoWrapper Exception
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Friday, January 30, 2009, 8:15:39 PM, Attila Szegedi wrote:
> Right -- Rhino changed the type of the Undefined.instance from
> Scriptable to Object in 1.6R2, but we released FreeMarker 2.3.x series
> with support for 1.6R1. We're kind of in a pickle here, as we
> guarantee backwards compatibility within 2.3.x series, so
> theoretically, we must continue supporting 1.6R1... which probably
> nobody uses anymore anyway, as it's 5 years old.
>
> I'd be inclined to just break our backwards compatibility guarantee
> promise here. Or I can make it use reflection, when there's no
> assumption of the type of the object as we only use it in a ==
> operator, so it doesn't really matter what type it is, however field
> references in Java are strongly typed, see this output from javap for
> RhinoWrapper:
>
> public freemarker.template.TemplateModel wrap(java.lang.Object)
> throws freemarker.template.TemplateModelException;
> Code:
> 0: aload_1
> 1: getstatic #7; //Field org/mozilla/javascript/
> Undefined.instance:Lorg/mozilla/javascript/Scriptable;
> ...
>
> Of course, this should now be
>
> 1: getstatic #7; //Field org/mozilla/javascript/
> Undefined.instance:Ljava/lang.Object;
>
> in order to not throw a linkage error.
Um... it works with Rhino 1.7R1 here, and there they already have
Object instead Scriptable. I didn't recompile or anything.
Anyway... what I don't get is why this is not working:
root = {};
root.foo = "bar";
And then in the template:
${foo}
and it says that "foo" is undefined. And listing .data_model?keysI get
a lot of Rhino-specific method names. Something happened with
org.mozilla.javascirpt.Wrapper.unwrap, or was it always like this? /-:
> A quick remedy would be if you recompiled FreeMarker against a new
> js.jar so that it properly links with it. To do this:
>
> 1. cd to your FreeMarker distro directory, and type "ant jar". This'll
> pull down all the dependencies over HTTP into the lib directory and
> build the JAR file.
> 2. Replace lib/js.jar with Rhino 1.7R2 js.jar
> 3. Remove lib/freemarker.jar
> 4. Remove build directory
> 5. "ant jar" again.
> 6. Take lib/freemarker.jar and use it in your project.
>
> Hope that helps. I'll remedy this once and for all for 2.3.16 though;
> promise.
>
> Attila.
>
> On 2009.01.30., at 17:13, Patrick Dobbs wrote:
>
>> Hi,
>>
>> Thanks for your quick reply. I should have stated the versions but
>> assumed I was doing some obviously wrong.
>>
>> Rhino 1.7R2
>>
>> Freemarker 2.3.15 (according to MANIFEST in the jar).
>>
>> Patrick
>>
>>
>>
>> Attila Szegedi wrote:
>>> What are the FreeMarker and the Rhino versions you are using? Rhino
>>> changed a declaration of the "Undefined.instance" variable in a
>>> manner
>>> that was not binary compatible, so certain combinations of Rhino and
>>> FreeMarker unfortunately exhibit this...
>>>
>>> Attila.
>>>
>>> On 2009.01.30., at 7:14, Patrick Dobbs wrote:
>>>
>>>> Hi,
>>>>
>>>> I'm trying to use Freemarker from a Rhino javascript script. I've
>>>> the
>>>> couple of related newsgroup posts on this, but not being that
>>>> familiar
>>>> with Freemarker I suspect I'm going something wrong.
>>>>
>>>> Below is the Rhino shell session.
>>>>
>>>> Thanks
>>>>
>>>> Patrick
>>>>
>>>>
>>>> js> importPackage(Packages.freemarker.template);
>>>>
>>>> js> cfg = new Configuration();
>>>> freemarker.template.Configuration@195dd5b
>>>> js> cfg.setObjectWrapper(new Packages ext.rhino.RhinoWrapper());
>>>> js> cfg.setDirectoryForTemplateLoading(new java.io.File("./
>>>> templates"));
>>>> js> root = {}
>>>> [object Object]
>>>> js> root.name="Joe";
>>>> Joe
>>>> js> root.age="7";
>>>> 7
>>>> js> out = new java.io.OutputStreamWriter(java.lang.System.out);
>>>> java.io.OutputStreamWriter@1dacccc
>>>> js> temp = cfg.getTemplate("test.ftl");
>>>> <tr>
>>>> <th>Name</th><td>${name}</td>
>>>> </tr>
>>>> <tr>
>>>> <th>Age</th><td>${age}</td>
>>>> </tr>
>>>> js> temp.process(root,out);
>>>>
>>>> Exception in thread "main" java.lang.NoSuchFieldError: instance
>>>> at freemarker.ext.rhino.RhinoWrapper.wrap(RhinoWrapper.java:21)
>>>> at
>>>> freemarker
>>>> .template.Template.createProcessingEnvironment(Template.java:356)
>>>> at freemarker.template.Template.process(Template.java:237)
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>> at
>>>> sun
>>>> .reflect
>>>> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword