@echo off
rem ---------------------------------------------------------------------------
rem 安装须知:预先安装了jdk,并设置了环境变量%java_home%、%path%、%classpath%
rem 笃行天下制作 http://hi.baidu.com/duxing 2010年5月18日8:42:24
rem 如果您更新了本文件,能分享给我吗?softor@vip.qq.com
rem ---------------------------------------------------------------------------
echo 运行前请确定您安装了jdk,并设置了环境变量%%java_home%%、%%path%%、%%classpath%%
echo.
if not "%java_home%" == "" goto build_runClass
echo 没有设置环境变量%java_home%,请设置后再安装!
echo.
goto over
:build_runClass
echo 正在创建runClass.bat到%java_home% ...
echo.
echo @ECHO OFF >"%java_home%\runClass.bat"
echo rem 将.class文件拖放到本批处理上就可以自动执行java命令,前提是你预先安装了jdk,并设置了环境变量%%java_home%% >>"%java_home%\runClass.bat"
echo rem 感谢“秋ㄖ/ty枫.叶”对我的指导,本程序99%是他的功劳:http://wenwen.soso.com/z/q193976651.htm >>"%java_home%\runClass.bat"
echo rem 笃行天下整理 http://hi.baidu.com/duxing 2010年5月18日8:42:29 >>"%java_home%\runClass.bat"
echo rem 如果您更新了本文件,能分享给我吗?softor@vip.qq.com >>"%java_home%\runClass.bat"
echo.>>"%java_home%\runClass.bat"
echo set thefile=%%1 >>"%java_home%\runClass.bat"
echo.>>"%java_home%\runClass.bat"
echo for %%%%i in (%%thefile%%) do ( >>"%java_home%\runClass.bat"
echo.>>"%java_home%\runClass.bat"
echo cd /d "%%%%~dpi" >>"%java_home%\runClass.bat"
echo.>>"%java_home%\runClass.bat"
echo java "%%%%~ni" >>"%java_home%\runClass.bat"
echo.>>"%java_home%\runClass.bat"
echo ) >>"%java_home%\runClass.bat"
echo.>>"%java_home%\runClass.bat"
echo pause >>"%java_home%\runClass.bat"
echo 创建runClass.bat到%java_home%完毕!
echo.
Execute a class from Windows Explorer
This HowTo will you show how to start a class (with a main() method) without opening a DOS Shell or using a JAR file directly from Windows Explorer.
Type the following VBScript using a text editor and save it as WRunJava.vbs.
You need to save the script in the SendTo subdirectory located in the Windows directory (eg. on a Win98 system, it's C:\Windows\SendTo).
Then in Window Explorer, locate a class file that can be executed (with a main() method). Right click on it, select the Send To menu and you should see an entry called WRunJava.vbs. Simply select it and the class should launched via javaw.exe .
' [WRunJava.vbs] start a java class without a console
Dim WSHShell, FSO, javaclass, javacompletepath, cmdline
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
If WScript.Arguments.Count = 0 Then
WScript.Echo "no argument on the command line."
Else
javaclass = WScript.Arguments(0)
If Not fso.GetExtensionName(javaclass) = "class" Then
WScript.Echo "Not a java class! (" & javaclass & ")"
Else
javacompletepath = fso.GetAbsolutePathName(javaclass)
javapath = fso.GetParentFolderName(javacompletepath)
javaclass = fso.GetBaseName(javaclass)
cmdline = "javaw.exe -cp " & javapath & " " & javaclass
WSHShell.Run cmdline, 1, false
End if
End If
Set WSHShell = Nothing
Set FSO = Nothing
WScript.Quit(0)
You can have a second script to lauch a java class with a console (useful to see debugging traces). Called it CRunJava.vbs . Then you will have two choices from the SendTo menu. ' [CRunJava.vbs] start a java class with a console
Dim WSHShell, FSO, javaclass, javacompletepath, cmdline
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
If WScript.Arguments.Count = 0 Then
WScript.Echo "no argument on the command line."
Else
javaclass = WScript.Arguments(0)
If Not fso.GetExtensionName(javaclass) = "class" Then
WScript.Echo "Not a java class! (" & javaclass & ")"
Else
javacompletepath = fso.GetAbsolutePathName(javaclass)
javapath = fso.GetParentFolderName(javacompletepath)
javaclass = fso.GetBaseName(javaclass)
cmdline = "java.exe -cp " & javapath & " " & javaclass
WSHShell.Run cmdline, 1, false
End if
End If