VJet は,次の機能を持つ Eclpse のプラグインです.Eclipse で JavaScript のプログラムを実行してみます
VJet の URL: https://projects.eclipse.org/projects/webtools.vjet
この Web ページで行うこと
VJET の要点
http://www.ebayopensource.org/svn/vjet/tags/RELEASE/plugin/
◆ Eclipse 4.2 (juno) での実行例
確認の後、「次へ (Next)」をクリック
【外部ページへのリンク】https://developers.google.com/eclipse/docs/install-eclipse-4.2
Eclipse 4.2 (juno) での設定例.「4.2」のところは Eclipse のバージョン番号に一致させること.
http://dl.google.com/eclipse/plugin/4.2
確認の後、「次へ (Next)」をクリック
確認の後、「次へ (Next)」をクリック
http://www.ebayopensource.org/svn/vjet/tags/RELEASE/plugin/
確認の後、「次へ (Next)」をクリック
静的 Web プロジェクト名は好きにつけて良いが,全角文字は避ける.分かりやすい名前が良い. ここでは,例として,次のように指定する.
既定のままでよい。「Finish (完了)」をクリック.
「はい」をクリック.
いま作成した静的 Web プロジェクトについて、次の手順で、VJET を有効にする
プロジェクト を右クリックし、 「VJET」→「Enable VJET Project Capabilities」と操作する.
ウインドウがエディタになっている。 編集が終わったら、<コントロールキー>+「S」(同時押し)で保存する.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> <script type="text/javascript" src="main.js"></script> </body> </html>
次のようなプログラムを書いてみる
編集が終わったら、<コントロールキー>+「S」(同時押し)で保存する.
document.write("Hello, World!");
※ 使用しているプラグインによっては表示が変わる場合がある.
Web サーバは、Eclipse に組み込みずみのものが起動する(「HTTP Preview」を選んだので).
※ サーバが起動しないときは、Eclipse のバグの可能性がある。 (下図のように、サーバビューで起動を試みても起動しない).
「サーバで実行」のあと、手動で、J2EEサーバを選ぶとうまくいく場合がある
先ほど作成した hoge.js を書き換え
document.writeln("<hr>"); document.writeln("<h1>hoge</h1>");
実行したいので、index.html を右クリックし、「Run As 」→「Run on Server」と操作する.
先ほど作成した hoge.js を書き換え
var a = 100; var b = a * 1.05; document.writeln("a = ", a); document.writeln("b = ", b);
実行したいので、index.html を右クリックし、「Run As 」→「Run on Server」と操作する.
先ほど作成した hoge.js を書き換え
function area(x) { var a = x * x * 3.14; return a; } var x = 100; document.writeln("x = ", x); document.writeln("area(x) = ", area(x));
実行したいので、index.html を右クリックし、「Run As 」→「Run on Server」と操作する.
先ほど作成した hoge.js を書き換え
var x = 100; document.writeln( "x =", x); document.writeln( JSON.stringify(x) ); var M = [0, 1, 2]; document.writeln( "M =", M); document.writeln( JSON.stringify(M) ); var t = {id:1, name:"hoge"}; document.writeln( "t =", t); document.writeln( JSON.stringify(t) );
実行したいので、index.html を右クリックし、「Run As 」→「Run on Server」と操作する.