ページ更新: 2012-04-16 (月) (3287日前)
2004-08-13 ECMAScriptのJavaによる実装 'Rhino' (らいの) に付いてのリンクとメモ。 目次 [編集]情報源 #[編集]Mozilla.org, Mozilla.gr.jp #Rhino - JavaScript for Java
Rhino - Java による JavaScript JavaScript Oracle #[編集]他 #特集: Java+スクリプト言語のイロハ
安藤幸央のランダウン:これは使える!Java風スクリプト Rhino nkaho の日記 (2741) Rhinoに関する覚え書き Mustang #リリースまで1年、Java SE 6"Mustang"の概要を一足早く把握する - 2005/8/16 Java (J2SE 6.0) Mustang(マスタング)の概要を先取り - 2005年06月15日 Core Java Technology Features in Mustang - June 16, 2005 以下引用
JSR 223: Scripting for the JavaTM Platform d.y.d. 7:37 05/09/27 Mustang (2005-10-25) Scripting Support in Mustang (Java News Brief - February 2006) Eclipse #本家のCVSになんかあるのだけど、2年以上たってるしなあ。 →Eclipse Monkey で復活? (2006-03-09) [編集]メモ #[編集]JavaScript Shell、JavaScript Debugger (2007-02-11) #いまさらだが、JavaScript Shell と JavaScript Debugger の起動方法をメモっておく。
注意:Rhino 1.6R5を使用、c:\java\rhino1_6R5 に展開してある。 JavaScript Shell (rhino.cmd) @echo off rem java -jar c:\java\rhino1_6R5\js.jar %* java -cp c:\java\rhino1_6R5\js.jar org.mozilla.javascript.tools.shell.Main %* JavaScript Debugger (rhinodbg.cmd) @echo off java -cp c:\java\rhino1_6R5\js.jar org.mozilla.javascript.tools.debugger.Main %*[編集] Context#evaluateString を実行するクラスから、ScriptableObject を継承したクラスに参照を渡す #2004-09-08 Examples には特にかかれていなかったので、Context#putThreadLocal, getThreadLocal を 使ってみた。 Context#evaluateString を実行するクラスで、Context#putThreadLocal(key, value) で渡して、 ScriptableObject を継承したクラスで、次のようにして受け取る。 (以下では、function sample(int) に渡した値を渡す例) public void jsFunction_sample(int value) { Context cx = Context.getCurrentContext(); Object o = cx.getThreadLocal(key); if (o instanceof Hogehoge) { Hogehoge hogehoge = (Hogehoge)o; // ... ここで処理する。 hogehoge.setValue(value); } } public interface Hogehoge { public void setValue(int value); }[編集] javaのクラスの使用を制限する #2004-09-08 Shutterを実装し、Context#set... に渡す。 Shutterでは、使用を許可する場合 true を、そうでない場合 false を返すこと。 (false を返すと、function not found、つまり未定義と見なされる) [編集]smalljs.jar を作る #2004-09-08 Small Footprint http://www.mozilla.org/rhino/footprint.html を参照。 Windows XP にて、J2SDK 1.4.2_05, Ant 1.5.4 を使用。 [編集]HTTP Proxy がない場合 #> ant smalljar Buildfile: build.xml properties: init: [mkdir] Created dir: C:\java\rhino1_5R5\build [mkdir] Created dir: C:\java\rhino1_5R5\build\classes [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5 [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5\src [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5\toolsrc [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5\examples [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5\docs [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5\docs\apidocs compile: properties: compile: [javac] Compiling 109 source files to C:\java\rhino1_5R5\build\classes [javac] C:\java\rhino1_5R5\src\org\mozilla\javascript\Context.java:1835: 警 告: org.mozilla.javascript の org.mozilla.javascript.WrapHandler は推奨されませ ん。 [javac] WrapHandler _handler; [javac] ^ [javac] C:\java\rhino1_5R5\src\org\mozilla\javascript\Context.java:1837: 警 告: org.mozilla.javascript の org.mozilla.javascript.WrapHandler は推奨されませ ん。 [javac] WrapHandlerProxy(WrapHandler handler) [javac] ^ [javac] C:\java\rhino1_5R5\src\org\mozilla\javascript\Context.java:1837: 警 告: org.mozilla.javascript の org.mozilla.javascript.WrapHandler は推奨されませ ん。 [javac] WrapHandlerProxy(WrapHandler handler) [javac] ^ [javac] 警告 3 個 [copy] Copying 2 files to C:\java\rhino1_5R5\build\classes properties: get-swing-ex: [get] Getting: http://java.sun.com/products/jfc/tsc/articles/treetable2/do wnloads/src.zip [unzip] Expanding: C:\java\rhino1_5R5\build\swingExSrc.zip into C:\java\rhin o1_5R5\toolsrc\org\mozilla\javascript\tools\debugger [delete] Deleting: C:\java\rhino1_5R5\toolsrc\org\mozilla\javascript\tools\de bugger\FileSystemModel2.java [delete] Deleting: C:\java\rhino1_5R5\toolsrc\org\mozilla\javascript\tools\de bugger\MergeSort.java [delete] Deleting: C:\java\rhino1_5R5\toolsrc\org\mozilla\javascript\tools\de bugger\TreeTableExample2.java compile: [javac] Compiling 22 source files to C:\java\rhino1_5R5\build\classes [copy] Copying 1 file to C:\java\rhino1_5R5\build\classes smalljar: [jar] Building jar: C:\java\rhino1_5R5\build\rhino1_5R5\smalljs.jar BUILD SUCCESSFUL Total time: 11 seconds[編集] HTTP Proxy がある場合 #ant smalljar の実行中に HTTP アクセスがあるため、失敗する。 (toolsrc/build.xml の get-swing-ex ターゲット) > ant smalljar Buildfile: build.xml properties: init: [mkdir] Created dir: C:\java\rhino1_5R5\build [mkdir] Created dir: C:\java\rhino1_5R5\build\classes [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5 [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5\src [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5\toolsrc [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5\examples [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5\docs [mkdir] Created dir: C:\java\rhino1_5R5\build\rhino1_5R5\docs\apidocs compile: properties: compile: [javac] Compiling 109 source files to C:\java\rhino1_5R5\build\classes [javac] C:\java\rhino1_5R5\src\org\mozilla\javascript\Context.java:1835: 警 告: org.mozilla.javascript の org.mozilla.javascript.WrapHandler は推奨されませ ん。 [javac] WrapHandler _handler; [javac] ^ [javac] C:\java\rhino1_5R5\src\org\mozilla\javascript\Context.java:1837: 警 告: org.mozilla.javascript の org.mozilla.javascript.WrapHandler は推奨されませ ん。 [javac] WrapHandlerProxy(WrapHandler handler) [javac] ^ [javac] C:\java\rhino1_5R5\src\org\mozilla\javascript\Context.java:1837: 警 告: org.mozilla.javascript の org.mozilla.javascript.WrapHandler は推奨されませ ん。 [javac] WrapHandlerProxy(WrapHandler handler) [javac] ^ [javac] 警告 3 個 [copy] Copying 2 files to C:\java\rhino1_5R5\build\classes properties: get-swing-ex: [get] Getting: http://java.sun.com/products/jfc/tsc/articles/treetable2/do wnloads/src.zip [get] Error getting http://java.sun.com/products/jfc/tsc/articles/treetabl e2/downloads/src.zip to C:\java\rhino1_5R5\build\swingExSrc.zip BUILD FAILED file:C:/java/rhino1_5R5/toolsrc/build.xml:23: java.net.UnknownHostException: jav a.sun.com Total time: 9 seconds たぶん System property で設定するか、Antのget task の username, password パラメータ、Setproxy タスクでできそうな気もするが、 とりあえず、http://java.sun.com/products/jfc/tsc/articles/treetable2/downloads/src.zip を ダウンロードして、swingExSrc.zip に変えて build\ に置き、 toolsrc/build.xml の該当個所をコメントアウト。 <target name="get-swing-ex" unless="swing-ex-available"> <!-- Download source from Sun's site, unzip it, remove the files we don't need, and change the package --> <!-- <get src="http://java.sun.com/products/jfc/tsc/articles/treetable2/downloads /src.zip" dest="${nest}/${build.dir}/swingExSrc.zip"/> --> <unzip src="${nest}/${build.dir}/swingExSrc.zip" dest="${src.debugger}"/> 再実行。 > ant smalljar Buildfile: build.xml properties: init: compile: properties: compile: properties: get-swing-ex: [unzip] Expanding: C:\java\rhino1_5R5\build\swingExSrc.zip into C:\java\rhin o1_5R5\toolsrc\org\mozilla\javascript\tools\debugger [delete] Deleting: C:\java\rhino1_5R5\toolsrc\org\mozilla\javascript\tools\de bugger\FileSystemModel2.java [delete] Deleting: C:\java\rhino1_5R5\toolsrc\org\mozilla\javascript\tools\de bugger\MergeSort.java [delete] Deleting: C:\java\rhino1_5R5\toolsrc\org\mozilla\javascript\tools\de bugger\TreeTableExample2.java compile: [javac] Compiling 22 source files to C:\java\rhino1_5R5\build\classes [copy] Copying 1 file to C:\java\rhino1_5R5\build\classes smalljar: [jar] Building jar: C:\java\rhino1_5R5\build\rhino1_5R5\smalljs.jar BUILD SUCCESSFUL Total time: 3 seconds これで、build\build\rhino1_5R5 に smalljs.jar (350,446 byte) が作成された。 [編集]最初に試す #Embedding Rhino http://www.mozilla.org/rhino/tutorial.html を見ながら、 Rhino を展開したディレクトリ (Rhino 1.5R5 なら rhino1_5R5 になる)の example を試す。 |