解决方案 »

  1.   

    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 consoleDim WSHShell, FSO, javaclass, javacompletepath, cmdlineSet 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 IfSet 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 consoleDim WSHShell, FSO, javaclass, javacompletepath, cmdlineSet 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 IfSet WSHShell = Nothing
    Set FSO = Nothing
     
      

  2.   

    最后一行陋了
    WScript.Quit(0)
      

  3.   

    Thanks,但我要的是雙擊.
    因該可以實現的。
      

  4.   

    楼上的说得对,把你的.class文件打包成.jar就可以了,如果你的程序不复杂,在jbuild5里面按提示搞很简单的。
      

  5.   


    我是想實現 雙擊如同在DOS中執行:java xxx一樣的功能。 
      

  6.   

    如果你得程序是没有界面的,那我还没用过,建议你写个.bat应该可以解决。
    如果是有界面的,用楼上的方法打个包,完全可以实现你说的要求,但如果你想用双击代替java ***命令,sorry,除了写批处理(.bat),没有方法。
      

  7.   

    http://www.csdn.net/expert/topic/389/389867.shtm
    自己看看 
      

  8.   

    @echo off
    rem ---------------------------------------------------------------------------
    rem 安装须知:预先安装了jdk,并设置了环境变量%java_home%、%path%、%classpath%
    rem 笃行天下制作 http://hi.baidu.com/duxing 2010年5月18日8:42:24
    rem 如果您更新了本文件,能分享给我吗?[email protected]
    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 如果您更新了本文件,能分享给我吗?[email protected] >>"%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.:associate
    echo.正在关联class文件打开方式到runClass.bat ...reg add HKEY_CLASSES_ROOT\classfile\DefaultIcon /f /ve /t REG_EXPAND_SZ /d "%java_home%\bin\java.exe,0"
    reg add HKEY_CLASSES_ROOT\classfile\shell\run\command /f /ve /t REG_EXPAND_SZ /d "\"%java_home%\runClass.bat\" \"%%1\""
    echo.
    echo.关联class文件完毕!
    echo.
    goto end:end
    echo.安装完毕!
    echo.:over
    pause
    转自:http://hi.baidu.com/duxing/blog/item/8fac42162eb48e4620a4e99e.html