- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在使用用于 GUI 呈现的 Eclipse SWT 库用 Java 编写桌面应用程序。我认为 SWT 帮助 Java 克服桌面上接受的最大障碍:即为 Java 应用程序提供一个一致的、响应式的界面,看起来就像属于你桌面上的任何其他应用程序一样。但是,我觉得打包一个应用程序仍然是一个问题。
OS X 原生提供了一种将 Java 应用程序包装在原生应用程序包中的简单机制,但是为 Windows/Linux 生成一个不需要用户运行丑陋的批处理文件或单击 .jar 的应用程序仍然很麻烦.在 Linux 上这可能不是这样的问题,用户可能更精通技术,但在 Windows 上,我希望有一个常规的 .exe 供他/她运行。
有没有人使用过任何用于 Java 的 .exe 生成工具?我尝试过 JSmooth,但遇到了各种问题。在我破解 Visual Studio 并自己动手之前有没有更好的解决方案?
编辑:我或许应该提一下,我无法在商业解决方案上花很多钱。
最佳答案
为了跟进 pauxu 的回答,我在我的一个项目中使用了 launch4j 和 NSIS,并认为展示我如何使用它们会有所帮助。这就是我正在为 Windows 做的事情。顺便说一句,我正在为 Mac 创建 .app 和 .dmg,但还没有弄清楚要为 Linux 做什么。
在我的项目中,我有一个“供应商”目录,在它下面有一个用于“launch4j”和“nsis”的目录。每个应用程序中都有一份安装副本。我发现将副本复制到项目本地比强制其他人安装这两种产品并设置某种环境变量来指向每个产品更容易。
我的项目中还有一个“脚本”目录,其中包含我的项目的各种配置/脚本文件。首先是launch4j.xml文件:
<launch4jConfig>
<dontWrapJar>true</dontWrapJar>
<headerType>gui</headerType>
<jar>rpgam.jar</jar>
<outfile>rpgam.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://www.rpgaudiomixer.com/</downloadUrl>
<supportUrl></supportUrl>
<customProcName>false</customProcName>
<stayAlive>false</stayAlive>
<manifest></manifest>
<icon></icon>
<jre>
<path></path>
<minVersion>1.5.0</minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
</jre>
<splash>
<file>..\images\splash.bmp</file>
<waitForWindow>true</waitForWindow>
<timeout>60</timeout>
<timeoutErr>true</timeoutErr>
</splash>
</launch4jConfig>
然后是 NSIS 脚本 rpgam-setup.nsis。它可以使用 VERSION 参数来帮助命名文件。
; The name of the installer
Name "RPG Audio Mixer"
!ifndef VERSION
!define VERSION A.B.C
!endif
; The file to write
outfile "..\dist\installers\windows\rpgam-${VERSION}.exe"
; The default installation directory
InstallDir "$PROGRAMFILES\RPG Audio Mixer"
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\RPG_Audio_Mixer" "Install_Dir"
# create a default section.
section "RPG Audio Mixer"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
File /r "..\dist\layout\windows\"
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\RPG_Audio_Mixer "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RPGAudioMixer" "DisplayName" "RPG Audio Mixer"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RPGAudioMixer" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RPGAudioMixer" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RPGAudioMixer" "NoRepair" 1
WriteUninstaller "uninstall.exe"
; read the value from the registry into the $0 register
;readRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" CurrentVersion
; print the results in a popup message box
;messageBox MB_OK "version: $0"
sectionEnd
Section "Start Menu Shortcuts"
CreateDirectory "$SMPROGRAMS\RPG Audio Mixer"
CreateShortCut "$SMPROGRAMS\RPG Audio Mixer\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\RPG AUdio Mixer\RPG Audio Mixer.lnk" "$INSTDIR\rpgam.exe" "" "$INSTDIR\rpgam.exe" 0
SectionEnd
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RPGAudioMixer"
DeleteRegKey HKLM SOFTWARE\RPG_Audio_Mixer
; Remove files and uninstaller
Delete $INSTDIR\rpgam.exe
Delete $INSTDIR\uninstall.exe
; Remove shortcuts, if any
Delete "$SMPROGRAMS\RPG Audio Mixer\*.*"
; Remove directories used
RMDir "$SMPROGRAMS\RPG Audio Mixer"
RMDir "$INSTDIR"
SectionEnd
我的 Ant 构建文件 (build.xml) 中有一些目标来处理上述问题。首先我 tel Ant 导入 launch4j 的 Ant 任务:
<property name="launch4j.dir" location="vendor/launch4j" />
<taskdef name="launch4j"
classname="net.sf.launch4j.ant.Launch4jTask"
classpath="${launch4j.dir}/launch4j.jar:${launch4j.dir}/lib/xstream.jar" />
然后我有一个简单的目标来创建包装器可执行文件:
<target name="executable-windows" depends="jar" description="Create Windows executable (EXE)">
<launch4j configFile="scripts/launch4j.xml" outfile="${exeFile}" />
</target>
以及制作安装程序的另一个目标:
<target name="installer-windows" depends="executable-windows" description="Create the installer for Windows (EXE)">
<!-- Lay out files needed for building the installer -->
<mkdir dir="${windowsLayoutDirectory}" />
<copy file="${jarFile}" todir="${windowsLayoutDirectory}" />
<copy todir="${windowsLayoutDirectory}/lib">
<fileset dir="${libraryDirectory}" />
<fileset dir="${windowsLibraryDirectory}" />
</copy>
<copy todir="${windowsLayoutDirectory}/icons">
<fileset dir="${iconsDirectory}" />
</copy>
<copy todir="${windowsLayoutDirectory}" file="${exeFile}" />
<mkdir dir="${windowsInstallerDirectory}" />
<!-- Build the installer using NSIS -->
<exec executable="vendor/nsis/makensis.exe">
<arg value="/DVERSION=${version}" />
<arg value="scripts/rpgam-setup.nsi" />
</exec>
</target>
上半部分只是将安装程序所需的文件复制到一个临时位置,后半部分执行使用所有文件来制作安装程序的脚本。
关于java - 为 Windows/Linux 桌面打包 Java 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7720/
我在使用 nuget 打包新包时遇到问题,因为当我通过命令行指定版本时,它会将它应用于包而不是依赖项。即 NuGet.exe pack myproject.csproj -Version 3.0.4.
考虑这个简短的例子: $a = pack("d",255); print length($a)."\n"; # Prints 8 $aa = pack("ddddd", 255,123,0,45,12
我有一个我想要的无符号整数数组(32 位) pack 成二进制流: my @n = (4,8,15,16,23,42); my $foo = join('', map(pack('I', $_), @
在我的工作中,我们必须在各种环境中部署应用程序。这是一个标准的 WAR 文件,需要一些配置,部署在 Tomcat 6 上。 有没有什么方法可以使用 Tomcat 创建一个“部署包”,以便您只需提取它并
我正在编写一个简单的数据包序列化程序,但我很难为我的数据包创建 header 。我正在创建一个缓冲区,然后尝试将前两项加载到缓冲区中。我运行 memcopy 但缓冲区中实际上没有任何内容,然后当我尝试
有人可以解释为什么当你有一个普通的小部件时,一行代码 A 可以工作 Entry(root, width=10).pack(side=LEFT,anchor=W) 但是当你给它命名或附加命令时,代码 A
我正在尝试使用this tutorial构建Python包。这是文件夹结构: testpackage\ testpackage\ __init__.py
我有 JFrame 和 GridBagLayout。用户可以调整此窗口的大小。此外,他还可以执行一些更改窗口大小的编辑操作。我使用 pack(); repaint(); 现在在这样的操作之后。但是,实
我有一个现实世界的问题,我认为需要某种优化,而不是对我关心的数据数组进行简单排序。我将在下面概述问题: 我有一个由不同设备组成的数据集,每个设备都有属性 A 和 B。A 和 B 彼此不依赖,但是,我想
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我必须将旧的“加密”数据从旧系统转换为适当的加密算法。我有这段代码: function unpackString($s,$l){ $tmp=unpack('c'.$l,$s);
我有两个发电机。第一个生成器有时需要调用第二个生成器并返回它从那里获得的值: def a(): for _b in b(): yield _b def b(): yie
首先:对不起,我知道有很多关于相对导入的问题,但我只是没有找到解决方案。如果可能的话,我想使用以下目录布局: myClass/ __init__.py test/ de
1 ambari + bigtop 构建大数据基础平台 1.1 参考: 1.2 参考 amabri bigtop 打包部署
所以 SimpleInjector 现在有一个包装 nuget,您可以使用它来隔离根组合的不同方面。 假设我在一个库中有一个可配置的组合根,它被应用程序中的多个项目重用。例如,在 Azure 解决方案
我想以易于分发的形式打包 Groovy CLI 应用程序,类似于 Java 对 JAR 所做的。我一直无法找到任何似乎能够做到这一点的东西。我发现了一些类似 this 的东西用于一次性脚本,但不能编译
目前 ZMI 管理“打包数据库”的功能有点粗糙。 1) 是否有可能为 Web UI 提供某种进度指示器?例如。一个告诉你还剩多少分钟/小时,至少给出某种估计 2) ZODB 打包如何影响站点的响应性?
我有一个看起来像这样的结构: struct vdata { static_assert(sizeof(uint8_t *) == 8L, "size of pointer must be 8");
我已经尝试打包/发布我的 Azure 项目有一段时间了(但没有成功)。我尝试过以下方法: 右键单击 -> 从 Visual Studio 打包/发布 (OutOfMemoryException) CS
我创建了一个 JavaScript 库,并将其打包为以下选定的选项:Shrink Variables和Base62 Encoded在这个网址:http://dean.edwards.name/pack
我是一名优秀的程序员,十分优秀!