美文网首页
打包工具inno setup

打包工具inno setup

作者: jaymz明 | 来源:发表于2022-04-11 17:24 被阅读0次

    好久好久没有更新了。不多提,写点好玩的。
    最近发现了一个打包工具,可以将war/jar 包应用打包成exe安装文件。当然市面上还有installanywhere,种种原因吧。这款工具比较轻量级。
    当我们想把一个应用快速的部署到客户机或者服务器上,或者分享给别人时,如果对方对软件不了解,或者对系统各个依赖也不知道的话,运维部署系统确实比价麻烦。
    innoSetup工具可以将系统依赖的东西都打包在一起。如下方的代码中我把系统依赖的jdk,数据库mysql以及运行需要的war和数据库初始脚本都放在一起,用户拿到exe文件,直接就像安装软件一样,将系统部署到了自己的机器上了。还是比较丝滑的。
    我的启动那个脚本呢,就是把相关的环境变量设为系统的,然后拉起mysql服务,并通过java -jar xxx.war 来启动我的应用。

    image.png Snipaste_2022-04-11_17-23-09.png
    ; Script generated by the Inno Setup Script Wizard.
    ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
    
    #define MyAppName "jxc"
    #define MyAppVersion "1.0"
    #define MyAppPublisher "jaymz, Inc."
    #define MyAppURL "https://www.example.com/"
    #define MyAppExeName "install.bat"
    #define MyAppAssocName MyAppName + " File"
    #define MyAppAssocExt ".myp"
    #define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt        
    #define MyJreName "jdk"
    #define MySQLName "mysql"
    
    [Setup]
    ; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
    ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
    AppId={{E3633164-5F50-4EB0-AF6A-BD87D7E701B9}
    AppName={#MyAppName}
    AppVersion={#MyAppVersion}
    ;AppVerName={#MyAppName} {#MyAppVersion}
    AppPublisher={#MyAppPublisher}
    AppPublisherURL={#MyAppURL}
    AppSupportURL={#MyAppURL}
    AppUpdatesURL={#MyAppURL}
    DefaultDirName={autopf}\{#MyAppName}
    ChangesAssociations=yes
    DisableProgramGroupPage=yes
    ; Uncomment the following line to run in non administrative install mode (install for current user only.)
    PrivilegesRequired=admin
    OutputDir=C:\jaymz
    OutputBaseFilename=jxc
    Compression=lzma
    SolidCompression=yes
    WizardStyle=modern
    ;PrivilegesRequired=poweruser
    
    [Languages]
    Name: "english"; MessagesFile: "compiler:Default.isl"
    
    [Tasks]
    Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
    
    [Files]
    Source: "C:\Users\jaymz\Desktop\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
    Source: "C:\Program Files\Java\jdk1.8.0_181\*"; DestDir: "{app}\{#MyJreName}"; Flags: ignoreversion recursesubdirs createallsubdirs 
    Source: "C:\project\jaymz\jxc\mysql-8.0.26-winx64\*"; DestDir: "{app}\{#MySQLName}"; Flags: ignoreversion recursesubdirs createallsubdirs
    Source: "C:\project\JXC\target\JXC.war"; DestDir: "{app}"; Flags: ignoreversion
    Source: "C:\project\jaymz\jxc\icon.png"; DestDir: "{app}"; Flags: ignoreversion
    ; Source: "C:\project\JXC\db_jxc.sql"; DestDir: "{app}"; Flags: ignoreversion
    ; NOTE: Don't use "Flags: ignoreversion" on any shared system files
    
    [Registry]
    Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue
    Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
    Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
    Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
    Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: ".myp"; ValueData: ""
    
    [Icons]
    Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\icon.png"
    Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\icon.png"; Tasks: desktopicon
    
    [Dirs]
    Name: {app}; Permissions: users-full
    [Run]
    Filename: "{app}\{#MyAppExeName}"; Flags: nowait postinstall skipifsilent shellexec
    
    

    启动脚本

    @echo off
    title jxc software is installing
    color 0a
    echo setting install in environment...
    setx /M JAVA_HOME "%~dp0%jdk"
    setx /M MYSQL_HOME "%~dp0%mysql-8.0.26-winx64"
    setx /M CLASS_PATH ".;%%JAVA_HOME%%\lib;"
    setx /M PATH "%PATH%;%%JAVA_HOME%%\bin;%%MYSQL_HOME%%\bin;"
    
    echo environment variables have been configed successfully.
    
    cd "%~dp0%"
    
    
    echo start to install database
    cd mysql
    
    bin\mysqld.exe --initialize-insecure 
    bin\mysqld.exe -install MySQL1.8
    net start MySQL1.8
    sc config MySQL1.8 start= auto
    echo database start...
    ping -n 3 127.1>nul
    echo initial the database...
    bin\mysqladmin.exe -u root password xxxx
    
    echo initial data in database
    bin\mysql.exe -u root -pxxx < db_jxc.sql
    
    
    echo database has been initial completed
    cd ..
    echo start application....
    
    set "JAVA_HOME=%~dp0%jdk"
    
    call java -jar xxx.war
    
    echo started...
    
    echo access localhost:8086 to land the service
    
    pause
    

    相关文章

      网友评论

          本文标题:打包工具inno setup

          本文链接:https://www.haomeiwen.com/subject/ruxwsrtx.html