Skip to content

Instantly share code, notes, and snippets.

@taka2
Created October 16, 2009 09:05
Show Gist options
  • Select an option

  • Save taka2/211661 to your computer and use it in GitHub Desktop.

Select an option

Save taka2/211661 to your computer and use it in GitHub Desktop.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>Java実行</title>
<style type = "text/css">
#btnExec
{
width: 200px;
height: 30px;
}
</style>
<script language = "VBScript">
Sub Window_onLoad
window.resizeTo 650,680
End Sub
Sub btnExec_Click
' 各種オブジェクトの生成
Set wsh = CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
' デスクトップフォルダの取得
strDesktopFolder = wsh.SpecialFolders("Desktop")
strSourceFile = strDesktopFolder & "\\Test.java"
strClassFile = strDesktopFolder & "\\Test.class"
strClassName = "Test"
' ソースファイルを保存
Set ts = fs.CreateTextFile(strSourceFile)
ts.Write(document.form1.source.value)
ts.Close()
' デスクトップよりjar/zipファイルを検索し、クラスパスに追加
classPath = """" & strDesktopFolder & """"
Set objDesktopFolder = fs.GetFolder(strDesktopFolder)
For Each desktopFile In objDesktopFolder.Files
If Right(desktopFile.Name, 4) = ".jar" Or Right(desktopFile.Name, 4) = ".zip" Then
classPath = classPath & ";""" & desktopFile.Path & """"
End If
Next
' コンパイル
Set oExec = wsh.Exec("javac -classpath " & classPath & " -d """ & strDesktopFolder & """ """ & strSourceFile & """")
Do While oExec.Status = 0
idTimer = window.setTimeout("PausedSection", 100, "VBScript")
Loop
' コンパイル結果の表示
compileMessage = ""
While oExec.StdErr.AtEndOfStream = False
msg = oExec.StdErr.ReadLine()
compileMessage = compileMessage & msg & vbCrLf
Wend
document.form1.compiler_message.value = compileMessage
' 実行
If fs.FileExists(strClassFile) Then
wsh.Run "java.exe -classpath " & classPath & " " & strClassName, 10, True
End If
' ファイル削除
fs.DeleteFile(strSourceFile)
If fs.FileExists(strClassFile) Then
fs.DeleteFile(strClassFile)
End If
End Sub
Sub PausedSection
window.clearTimeout(idTimer)
End Sub
</script>
</head>
<body>
<form name = "form1">
<p>
ソースコード:<br>
<textarea name = "source" cols = "80" rows = "25">
public class Test
{
public static void main(String[] args)
{
try
{
// ここにコードを書く
System.out.println("Hello, Java World!");
}
catch(Exception e) { e.printStackTrace(); }
finally {
try {
System.out.println("Enterを押下してプログラムを終了してください。");
System.in.read();
} catch(java.io.IOException e) { /* 無視 */ }
}
}
}
</textarea>
<p>
<input id = "btnExec" type = "button" name = "btnExec" value = "実行" onClick = "btnExec_Click">
</p>
</p>
<p>
コンパイラメッセージ:<br>
<textarea name = "compiler_message" cols = "80" rows = "10" readonly>
</textarea>
</p>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment