什么是在Windows 7上启动Java应用程序的最佳方式? [英] What's the best way to start Java applications on Windows 7?

查看:218
本文介绍了什么是在Windows 7上启动Java应用程序的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows 7发布的Java GUI应用程序这个应用程序是使用Swing工具包,不需要任何本地code。该应用程序是使用 NSIS 安装程序进行安装。我想这个集成应用到Windows 7尽可能好。这意味着:

I want to publish a Java GUI application on Windows 7. This application is using the Swing Toolkit and doesn't need any native code. The application is installed using an NSIS installer. I want to integrate this application into Windows 7 as good as possible. This means:


  • 当应用程序正在运行,必须能引脚的应用到任务栏。

  • 必须能够将数据文件与应用程序相关联因此Windows中打开这些文件,我的申请。

  • 必须自动与32位Java运行时,并与64位Java运行时的工作。因此,当用户卸载了32位Java,并安装64位Java代替(反​​之亦然),那么我的应用程序必须仍然有效。

  • 必须支持大字体的Windows设置。我真的不明白这个功能。我只知道,有些应用程序完全忽略它,其他人(如谷歌浏览器)是像素缩放(看起来真的很丑)等人通过简单地使用较大的字体作为旨在支持它(这就是我想要的,通常它的工作原理,只有WinRun4J解决方案下面提到不使用它)。

WinRun4j 是一个EXE文件,启动Java应用程序。由于应用程序不会产生一个新的Java进程Windows认为该EXE文件是应用程序。所以没有与在任务栏没有问题。文件关联的工作,因为该文件可以用EXE文件可以简单地关联。

WinRun4j is an EXE file which launches the Java application. Because the application doesn't fork a new Java process Windows thinks the EXE file IS the application. So there is no problem with the taskbar. File associations works because the files can be simply associated with the EXE file.

问题:


  • 不支持大字体。应用程序窗口像素缩放,而不是(像谷歌浏览器)。

  • 两个不同的EXE文件必须根据安装JRE上使用。所以在安装时,64位JRE然后应用程序必须使用64位EXE文件开始。当再装32位JRE插件必须使用其他的EXE。这不是用户友好的,因为用户不理解为什么他只能在32位安装JRE在64位操作系统上使用32位的EXE。

Launch4J 创建一个32位的EXE会启动外部Java进程来启动Java应用程序。所以不像WinRun4J它也可以启动一个64位Java。

Launch4J creates a 32 bit EXE which launches an external Java process to start the Java application. So unlike WinRun4J it can also start a 64 bit Java.

问题:


  • 无法引脚的应用到任务栏。

  • 的System.out.println 将无法打印到控制台如果 headerType =桂,不管应用程序是从控制台启动。

  • Can't pin the application to the taskbar.
  • System.out.println will not print to console if headerType="gui", regardless if application is started from console.

在Windows上,可以只需双击JAR文件来启动应用程序。安装JRE不要紧,只要工作。但是......

On Windows you can simply double click the JAR file to start the application. Installed JRE doesn't matter, simply works. But...

问题:


  • 应用程序不能固定到任务栏。

  • 不能创建在开始菜单的快捷方式。

  • 无法文件,一个JAR文件相关联。

这样一个简单的批处理文件可用于启动应用程序:

A simple batch file like this can be used to start the application:

@echo off
start c:\windows\system32\javaw.exe -jar "c:\program files\myapp\myapp.jar" %1

一个快捷方式可以为这个批处理文件来设置自定义图标来创建。

A shortcut can be created for this batch file to set a custom icon.

问题:


  • 在应用程序启动时,一个DOS窗口弹出。

  • 的批处理文件,不知道从哪里javaw.exe的所在。这取决于Java版本(32位或64位)安装它可能位于 C:\\ WINDOWS \\ SysWow64资料而不是和Windows不会自动重定向从批处理文件这个调用。使用 JAVA_HOME 环境变量也是一个不走因为Java不设置这个自动。

  • 在当前文件,批处理文件相关联则没有自定义图标可以设置。

  • 任务栏的支持不能正常工作。当批处理文件手动启动,但是当双击关联的文件,而不是那么它不'工作中的应用可以固定它。

  • A DOS window pops up when the application is started.
  • The batch file doesn't know where javaw.exe is located. Depending on which java version (32 or 64 bit) is installed it may be located in c:\windows\syswow64 instead and Windows doesn't redirect this call from batch files automatically. Using the JAVA_HOME environment variable is also a no-go because Java doesn't set this automatically.
  • When associating files with the batch file then no custom icon can be set.
  • Taskbar support isn't working properly. Application can be pinned to it when the batch file is started manually but when double clicking an associated file instead then it doesn' work.

而不是使用一个批处理文件,它可以只创建一个快捷方式启动的应用程序。它链接到这个命令: C:\\ WINDOWS \\ SYSTEM32 \\ javaw.exe的罐子C:\\ Program Files文件\\ MyApp的\\ myapp.jar。 Windows会自动重定向该呼叫如果安装了32位Java JRE的Syswow64资料目录。

Instead of using a batch file it is possible to only create a shortcut to start the application. It links to this command: c:\windows\system32\javaw.exe -jar "c:\program files\myapp\myapp.jar". Windows automatically redirects this call to the SysWOW64 directory if a 32 bit Java JRE is installed.

问题:


  • 不可能因为Windows只接受EXE / COM / PIF / BAT / CMD文件作为联想的目标将文件与其关联。 LNK文件不起作用。

有其满足上面所有的要求,另一种解决方案?还是有什么招数来解决所提到的解决方案的问题?

Is there another solution which fulfills all the requirements from above? Or are there any tricks to solve the problems with the mentioned solutions?

使用 Launch4j 解决任务栏上,寄希望于问题后看起来像最好的解决方案。 Launch4j可以很容易地集成到Maven项目(含或的这个插件),配置为pretty容易,一切工作开箱即用,除了任务栏固定功能。对于任务栏上,寄托在Java应用程序必须设置一个appModelUserId作为答案解释这问题

After solving the taskbar-pinning problem using Launch4j looks like the best solution. Launch4j can easily be integrated into a Maven project (With this or this plugin), configuration is pretty easy and everything works out of the box except taskbar pinning. For taskbar-pinning the Java application must set an appModelUserId as explained in the answer to this question.

此外,Java应用程序必须通过它必须至少安装一个快捷方式指向的EXE安装程序进行安装。此快捷键还必须包含appModelUserId。随着NSIS这可以与 WinShell插件要做,这样的配置:

Additionally the Java application must be installed by an installer which must at least install one shortcut pointing to the EXE. This shortcut must also contain the appModelUserId. With NSIS this can be done with the WinShell plugin and a configuration like this:

CreateShortCut "$SMPROGRAMS\MyApp.lnk" \
    "$INSTDIR\myapp.exe" "" "$INSTDIR\myapp.exe" 0 SW_SHOWNORMAL
WinShell::SetLnkAUMI "$SMPrograms\MyApp.lnk" "MyAppModelUserId"

有关某些未知的原因,这个快捷键只有存在。你不必使用它。您可以双击EXE和任务栏钉扎仍然有效。你甚至可以在你的应用程序文件夹的子文件夹中的一些创建快捷方式。任务栏钉扎停止时的EXE文件的最后一个快捷方式删除工作。

For some unknown reason this shortcut only has to exist. You don't have to use it. You can double-click the EXE and taskbar-pinning still works. You can even create the shortcut in some subfolder of your application folder. Taskbar-pinning stops working when the last shortcut of the EXE file is removed.

推荐答案

尝试Launch4j( http://launch4j.sourceforge.net/),它的一个简单的jar到exe包装(实际包装罐是可选的)。它应该解决您的图标和任务栏的要求。它还能定位安装了JRE的(某些配置的规则)。字体的问题我不太搞定,秋千会自动使用的字体取决于Windows设置,除非你以某种方式覆盖在JRE选项或code。

Try Launch4j (http://launch4j.sourceforge.net/), its a simple jar to exe wrapper (actually wrapping the jar is optional). It should solve your Icon and Taskbar requirements. Its also capable locating installed JRE's (some configurable rules). The font problem I don't quite get, Swing should automatically use fonts depending on Windows settings, unless you somehow overwrite that in the JRE options or in code.

这篇关于什么是在Windows 7上启动Java应用程序的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆