如何为Java程序创建MSI Windows安装程序? [英] How to create a MSI Windows installer for a Java program?

查看:72
本文介绍了如何为Java程序创建MSI Windows安装程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Java程序创建一个Microsoft Installer文件.我不能使用Netbeans或任何Maven插件来执行此操作,因为我不能使用Oracle Java和/或JavaFX(主要出于法律原因),而且两者似乎都使用Oracle本机部署+ JavaSE 1.8.

I'd like to create a single Microsoft Installer file for a Java program. I can't use Netbeans or any Maven plugin to do it because I can't use Oracle Java and/or JavaFX (mainly for legal reasons) and both seem to use Oracle native deployment + JavaSE 1.8.

  • Java运行时环境(OpenJDK 1.7 JRE)
  • 脚本(.bat)
  • 胖的JAR
  • 图标文件
  • 一些文本文件
  • 我不想使用系统的JRE,这就是为什么我提供另一个JRE的原因.该脚本仅使用几个参数调用JRE.图标文件为.ico格式.胖JAR是包含所有必需的Java类,本机库和资产(包括第三方库)的JAR.

    I don't want to use the JRE of the system, that's why I provide another JRE. The script just calls the JRE with a few arguments. The icon file is in .ico format. The fat JAR is the JAR containing all necessary Java classes, native libraries and assets, including the third party libraries.

    我想允许最终用户安装,运行和卸载我的程序.我想在开始菜单中提供一个快捷方式来运行它,并提供另一个卸载它.似乎可以在此处中进行解释.我是否需要使用其他任何方式来创建卸载程序的快捷方式?

    I'd like to allow the end user to install, run and uninstall my program. I want to provide one shortcut in the start menu to run it and another one to uninstall it. It seems to be explained here. Do I have to use anything else to create a shortcut to uninstall my program?

    我已经看了Wix Toolset几周了.我知道我必须编写一个wxs文件以与"candle.exe"一起使用,它会创建一个wixobj文件,我必须对该文件运行"light.exe",然后得到一个MSI文件.

    I've looked at Wix Toolset for several weeks. I understand that I have to write a wxs file to use with "candle.exe", it creates a wixobj file, I have to run "light.exe" with this file and I get a MSI file.

    我知道如何添加文件,此处,但是我不知道如何添加包含JRE的整个目录而不一一提及每个文件.如何在wxs文件中完成?

    I know how to add a file, it's explained here but I don't know how to add the whole directory containing the JRE without mentioning each file one by one. How can it be done in the wxs file?

    如何选择一些独特的GUID?

    How to pick some unique GUIDs?

    是否已有一个(更多?)简单的工具可以用来从胖JAR制作MSI文件?在尝试以编程方式在GNU Linux下使用Apache POI进行相同操作之前,我更喜欢先了解如何在Windows下在命令行中构建这样的文件.

    Is there already a (more?) simple tool that I can use to make a MSI file from a fat JAR? I prefer understanding how to build such a file in command line under Windows first before trying to do the same programmatically with Apache POI under GNU Linux.

    编辑.:这是我的第一个wxs文件:

    Edit.: This is my first wxs file:

    <?xml version="1.0" encoding="utf-8"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
      <Product Id="*" Name="Truly Unusual Experience of Revolution" Language="1033" Version="0.0.0.0" Manufacturer="Julien Gouesse" UpgradeCode="00000000-0000-0000-0000-000000000000">
        <!-- Installer's Icon in Add/Remove Programs -->
    	<Icon Id="icon.ico" SourceFile="tuerLogo.ico"/>
        <Property Id="ARPPRODUCTICON" Value="icon.ico" />
    	<!-- Installer's version = 200 because the 64-bit support is required -->
        <Package InstallerVersion="200" InstallPrivileges="elevated" InstallScope="perMachine" Compressed="yes" Platform="x64" />
        <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
        <MajorUpgrade AllowDowngrades="yes" IgnoreRemoveFailure="yes" Schedule="afterInstallInitialize" />
        <Condition Message="This application is only supported on Windows XP, Windows Vista, Windows Server 2008, or higher.">
          <![CDATA[Installed OR (VersionNT >= 501)]]>
        </Condition>
        <Directory Id="TARGETDIR" Name="SourceDir">
          <Directory Id="ProgramFilesFolder">
            <Directory Id="APPLICATIONROOTDIRECTORY" Name="Truly Unusual Experience of Revolution">
    		  <Component Id="tuer.bat" Guid="00000000-0000-0000-0000-000000000000">
                <File Id="tuer.bat" Source="tuer.bat" KeyPath="yes"/>
    		  </Component>
    		  <Component Id="tuer.jar" Guid="00000000-0000-0000-0000-000000000000">
                <File Id="tuer.jar" Source="tuer.jar" KeyPath="yes"/>
    		  </Component>
    		  <Component Id="LICENSE.txt" Guid="00000000-0000-0000-0000-000000000000">
                <File Id="LICENSE.txt" Source="LICENSE.txt" KeyPath="yes"/>
    		  </Component>
    		  <Component Id="NOTICE.txt" Guid="00000000-0000-0000-0000-000000000000">
                <File Id="NOTICE.txt" Source="NOTICE.txt" KeyPath="yes"/>
    		  </Component>
    		  <Component Id="README.txt" Guid="00000000-0000-0000-0000-000000000000">
                <File Id="README.txt" Source="README.txt" KeyPath="yes"/>
    		  </Component>
    		</Directory>
          </Directory>
    	  <Directory Id="ProgramMenuFolder">
            <Directory Id="ApplicationProgramsFolder" Name="Truly Unusual Experience of Revolution"/>
          </Directory>
    	</Directory>
    	<!-- Shortcut in the Start Menu -->
    	<DirectoryRef Id="ApplicationProgramsFolder">
          <Component Id="ApplicationShortcut" Guid="00000000-0000-0000-0000-000000000000">
            <Shortcut Id="ApplicationStartMenuShortcut" 
                      Name="Truly Unusual Experience of Revolution" 
                      Description="First person shooter"
                      Target="[#tuer.bat]"
                      WorkingDirectory="APPLICATIONROOTDIRECTORY"
    			      Icon="icon.ico" />
              <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
              <RegistryValue Root="HKCU" Key="Software\Microsoft\TrulyUnusualExperienceofRevolution" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
          </Component>
        </DirectoryRef>
        <Feature Id="TrulyUnusualExperienceofRevolution" Title="Truly Unusual Experience of Revolution" Level="1">
    	  <ComponentRef Id="tuer.bat" />
    	  <ComponentRef Id="tuer.jar" />
    	  <ComponentRef Id="LICENSE.txt" />
    	  <ComponentRef Id="NOTICE.txt" />
    	  <ComponentRef Id="README.txt" />
    	  <ComponentRef Id="ApplicationShortcut" />
    	</Feature>
      </Product>
    </Wix>

    Edit.2:是通过在JRE上运行"heat"获得的文件目录.

    Edit.2: This is the file obtained by running "heat" on the JRE directory.

    注意:,我没有回答自己的问题,但是当我发现使用NSIS构建安装程序时,我停止了调查( Nullsoft可编写脚本的安装系统)会容易得多,因为已经有 Java启动器的脚本,以在您的软件和操作系统中查找JRE(即使我建议您将OpenJDK JRE捆绑在软件中,以确保即使在操作系统中进行了更新或缺少JRE的情况下,OpenJDK JRE仍然可以正常工作),请

    N.B: I don't answer to my own question but I stopped investigating when I discovered that building an installer with NSIS (Nullsoft Scriptable Install System) would be a lot easier because there are already an Ant task and some packages for several GNU Linux distros (including Mageia, Fedora, ...) to make it work. You can find a script called Java Launcher to look for a JRE in your software and in your operating system (even though I advise you to bundle an OpenJDK JRE in your software to ensure that it will go on working despite the updates or the absence of a JRE in the operating system), another script with automatic JRE installation and a rudimentary example of nsi script for a Java based software.

    PS:顺便说一句,我现在使用我自己的工具(在内部使用Redline RPM),它是完全记录的开源软件(在GPL下),并且适用于RPM,DEB,APP和EXE(通过NSIS)它也被称为 Java本机部署工具包.

    P.S: By the way, I now use my own tool (which uses Redline RPM under the hood), it's fully documented, open source (under GPL), and works for RPM, DEB, APP and EXE (via NSIS) too, it's called Java Native Deployment Toolkit.

    推荐答案

    javapackager 包括打包MSI安装程序(使用WIX)的功能,该安装程序包括针对已安装应用程序的自定义JRE安装.如果您不希望使用Oracle Java附带的打包程序,或者不希望使用从OpenJDK源代码编译的打包程序,则可以查看

    The javapackager from the OpenJDK project for Java 8/9 includes the ability to package MSI installers (using WIX) that include custom JRE installations for the installed application. If you don't wish to use the packager provided with Oracle Java or one that you compile from the OpenJDK source, maybe reviewing the javapackager source code might help you to create your own packaging utilities.

    许可似乎是您关心的问题-因此,如果采用此路径,则可以检查 OpenJDK合法文件适合您的情况.请注意,如果您使用OpenJDK,则 Oracle BCL 是不适用.

    Licensing seems to be a concern for you - so if you adopt this path, you can check that the OpenJDK legal documents are amenable to your situation. Note that if you use OpenJDK, the Oracle BCL is not applicable.

    我没有详细检查javapackager的源代码,但是它可能对Java 8的功能有些依赖.由于您的目标是创建基于JRE 7的程序包,因此您也许可以使用Java 8运行时来执行打包程序,但可以将Java 7 JRE打包为目标程序.如果必须使用Java 7运行时来运行打包工具,并且打包程序代码使用Java 8功能-您可以将其分叉并将其反向移植到Java 7(您将需要一些非常严格的要求才能做到这一点-大多数人不会有这样的要求).

    I have not checked the javapackager source in detail, but it may have some reliance on Java 8 features. As your target is to create a JRE 7 based package, you might be able to use a Java 8 runtime to execute the packager, but package a Java 7 JRE as a target. If you must run the packaging tools using a Java 7 runtime and the packager code uses Java 8 features - you could fork it and backport it to Java 7 (you would need some pretty strict requirements to require this - most people would not have such requirements).

    我不建议您将上述方法作为完成任务的最理想方法-我只是抛出一些对您可能有用或可能无用的想法.

    I'm not recommending the above as the most ideal way to accomplish your task - I'm just throwing out some ideas which might or might not be useful to you.

    这篇关于如何为Java程序创建MSI Windows安装程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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