简体   繁体   English

如何为最终用户方便地启动Java GUI程序

[英]How to start Java GUI program conveniently for the end user

The user wants to start the Java GUI application from Windows , with some amount of additional JVM parameters. 用户希望从Windows启动Java GUI应用程序,并添加一些额外的JVM参数。
For instance: 例如:

javaw -Djava.util.logging.config.file=logging.properties -jar MyGUI.jar

If I add the above line to the batch file, the user can double-click the batch-file name. 如果我将上述行添加到批处理文件中,则用户可以双击批处理文件名。
And it's cool. 而且很酷。 But there is one annoying side effect: the batch file opens the cmd window before starting the GUI . 但是有一个恼人的副作用: 批处理文件在启动GUI之前打开cmd窗口

Is there a simple way to start the java GUI application by double-clicking the batch-file (or some other file which suits the above needs) without opening the cmd window? 是否有一种简单的方法可以通过双击批处理文件(或其他适合上述需要的文件)来启动java GUI应用程序而无需打开cmd窗口?

I see a number of ways: 我看到了很多方法:

  • Use a launcher as generated by Launch4J (thanks to CodeBrickie for the tip) or Install4J/Exe4J . 使用Launch4J生成的启动器(感谢CodeBrickie提示)或Install4J / Exe4J Launch4J allows you to tweak the parameters by creating an .l4j.ini file with the same name as the exe. Launch4J允许您通过创建与exe同名的.l4j.ini文件来调整参数。 In case of Exe4J, extra parameters can be specified in a .vmoptions file which you drop next to the generated exe. 对于Exe4J,可以在.vmoptions文件中指定额外的参数,该文件将放在生成的exe旁边。
  • Create a Shortcut to javaw.exe, give it the icon you want, set the "Start in" field to the directory of the application and specify your parameters to javaw in the Target field. 创建javaw.exe的快捷方式,为其指定所需的图标,将“开始”字段设置为应用程序的目录,并在“目标”字段中为javaw指定参数。
  • Make a VB script which launches javaw. 制作一个启动javaw的VB脚本。 If the VBS runtime is set to use wscript , no console window will pop up. 如果VBS运行时设置为使用wscript ,则不会弹出控制台窗口。
  • If you use Java Web Start, you might want to let the user tweak the JNLP file as specified in Java Webstart with parameters . 如果您使用Java Web Start,您可能希望让用户使用参数调整Java Webstart中指定的JNLP文件。

Try 尝试

start javaw -Djava.util.logging.config.file=logging.properties -jar MyGUI.jar

You can also use scripting : 您还可以使用脚本

VBS: VBS:

Const HIDDEN_WINDOW = 12 

strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set objStartup = objWMIService.Get("Win32_ProcessStartup") 

Set objConfig = objStartup.SpawnInstance_ 
objConfig.ShowWindow = HIDDEN_WINDOW 
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process") 
errReturn = objProcess.Create("Notepad.exe", null, objConfig, intProcessID)

JScript: JScript的:

var WindowStyle_Hidden = 0
var objShell = WScript.CreateObject("WScript.Shell")
var result = objShell.Run("cmd.exe /c abc.bat", WindowStyle_Hidden)

Finally, there are general-purpose utilities you can use to hide windows, such as CMDOW and Hidden Start ($20) . 最后,您可以使用通用实用程序来隐藏窗口,例如CMDOWHidden Start(20美元) I have not used either myself, since start does the same thing. 我没有使用过自己,因为start做同样的事情。

The user wants to start the Java GUI application .. 用户想要启动Java GUI应用程序..

The best user experience for the end user will be offered by launching the app. 通过启动应用程序,将为最终用户提供最佳用户体验。 using Java Web Start . 使用Java Web Start JWS can install desktop shortcuts and menu items to launch the app. JWS可以安装桌面快捷方式和菜单项来启动应用程序。

..from Windows.. ..来自Windows ..

JWS also works on OS X & *nix. JWS也适用于OS X&* nix。

Lauch4j可以将你的jar包装在exe文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM