PDA

View Full Version : Javascript scripts and Classpaths



kettle_sethladd
04-05-2006, 03:56 PM
Hello,


I'm trying to write a simple Javascript transform that SHA1 hashes a field. I am trying to use a small class that performs the hashing, yet I can't seem to load it up in the script itself. I've placed the .jar into the libext and modified the spoon.bat file to include the .jar in the classpath.



Anytime I try to access the custom class, I receive a "Reference Error: "org" is not defined". In this case, "org" is the first element of the package name.



My script contains:



var hashed = org.apache.commons.codec.digest.DigestUtils.shaHex(ssn.getString());



Any ideas on how to get arbitrary .jars into the classpath so that I can use them in the Javascript scripts? Thanks!

kettle_sethladd
04-05-2006, 04:36 PM
To answer my own question, here's how you can refer to classes in arbitrary packages:


var hashed = Packages.org.apache.commons.codec.digest.DigestUtils.shaHex(ssn.getString());



Notice the use of Packages prefix to the package name.

MattCasters
04-06-2006, 11:24 AM
I really like it when you guys start to reply to your own questions ;-)



Thanks for the tip. I am not a Rhino expert myself.



There are some nice tips to be found on scripting on the Rhino website as well: http://www.mozilla.org/rhino/



Cheers,

Matt