使用Inno Setup 打包jdk、mysql、tomcat、webapp等爲一個exe安裝包

  以前一直都沒涉及到打包安裝方面的東西,都是另外一個同事負責的,使用的工具(installshield)也比較高大上一點,但是後來他離職之後接受的同事也只能是在這個基礎上作個簡單的配置,而後打包,但是如今作的項目和原來的徹底不同之後就不能使用以前的了,只能是本身硬着頭皮來弄個比較簡單快捷的了。java

  切入正題,如標題所述使用inno setup來打包一個java web 相關的內容爲一個exe,.net web相似,這個工具能夠在網上直接找到下載,有漢化版的,而且裏面也有幫助手冊能夠參考。把裏面的一些敏感信息已經作了替代,這些都是能夠根據你本身狀況來修改的。下面直接上乾貨。mysql

  • 打包和發佈的內容
    jdk(1.6/1.7/1.8)、mysql(5.5~)、tomcat(6.0/7.0/8.0)、ftp服務器、webapp、.Net服務、C++服務(請諸位無視項目中技術的複雜行,都是歷史緣由)
    打包腳本和bat腳本中涉及到,文件拷貝、ini配置文件修改、xml配置文件修改、服務安裝中止啓動、.net服務安裝、環境變量配置、數據庫初始化等,惟獨缺乏註冊表和防火牆配置(%>_<%)
  • 打包腳本
      1 ; 腳本由 Inno Setup 腳本嚮導 生成!
      2 ; 有關建立 Inno Setup 腳本文件的詳細資料請查閱幫助文檔!
      3 
      4 #define MyAppName "abc"
      5 #define MyAppVersion "1.0"
      6 #define MyAppPublisher "aaa"
      7 #define MyAppURL "http://www.abc.com/"
      8 
      9 [Setup]
     10 ; 注: AppId的值爲單獨標識該應用程序。
     11 ; 不要爲其餘安裝程序使用相同的AppId值。
     12 ; (生成新的GUID,點擊 工具|在IDE中生成GUID。)
     13 AppId={{9E044575-9CD9-4751-B0BE-F6758BA94548}
     14 AppName={#MyAppName}
     15 AppVersion={#MyAppVersion}
     16 ;AppVerName={#MyAppName} {#MyAppVersion}
     17 AppPublisher={#MyAppPublisher}
     18 AppPublisherURL={#MyAppURL}
     19 AppSupportURL={#MyAppURL}
     20 AppUpdatesURL={#MyAppURL}
     21 DefaultDirName={pf}\{#MyAppName}
     22 DefaultGroupName=XX管理軟件(abc)
     23 AllowNoIcons=yes
     24 OutputBaseFilename=setup
     25 Compression=lzma
     26 SolidCompression=yes
     27 [Files]
     28 ;拷貝tomcat
     29 Source:"Source\apache-tomcat-6.0.41\*";DestDir:"{app}\tomcat6.0";Flags:igNoreversion recursesubdirs createallsubdirs
     30 ;拷貝jdk
     31 Source:"Source\jdk1.6.0_43\*";DestDir:"{app}\jdk1.6";Flags:igNoreversion recursesubdirs createallsubdirs
     32 ;拷貝mysql
     33 Source:"Source\MySql5.5\*";DestDir:"{app}\MySql5.5";Flags:igNoreversion recursesubdirs createallsubdirs
     34 ;拷貝源代碼
     35 Source:"Source\abc\*";DestDir:"{app}\tomcat6.0\webapps\ROOT";Flags:igNoreversion recursesubdirs createallsubdirs
     36 ;拷貝sdk
     37 Source:"Source\Sdk\*";DestDir:"{app}\Sdk";Flags:igNoreversion recursesubdirs createallsubdirs
     38 ;拷貝服務器
     39 Source:"Source\Server\*";DestDir:"{app}\Server";Flags:igNoreversion recursesubdirs createallsubdirs
     40 ;拷貝ftp
     41 Source:"Source\FtpServer\*";DestDir:"{app}\FtpServer";Flags:igNoreversion recursesubdirs createallsubdirs
     42 ;拷貝bat
     43 Source:"Source\*";DestDir:"{app}\";
     44 ;拷貝桌面快捷方式
     45 Source:"Source\xx系統.url";DestDir:"{userdesktop}\xx系統";
     46 [Languages]
     47 Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"
     48 [Icons]
     49 Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}"
     50 Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
     51 [INI]
     52 ;修改數據庫配置文件
     53 Filename:"{app}\MySql5.5\my.ini";Section:"mysqld";Key:"basedir"; String:"{app}\MySql5.5"
     54 Filename:"{app}\MySql5.5\my.ini";Section:"mysqld";Key:"datadir"; String:"{app}\MySql5.5\data"
     55 Filename:"{app}\MySql5.5\my.ini";Section:"mysqld";Key:"port"; String:"3308"
     56 Filename:"{app}\MySql5.5\my.ini";Section:"client";Key:"port"; String:"3308"
     57 ;修改服務器配置文件
     58 Filename:"{app}\Server\init.ini";Section:"RegAddr";Key:"port"; String:"5556"
     59 Filename:"{userdesktop}\xx系統.url";Section:"InternetShortcut";Key:"URL"; String:"http://127.0.0.1:7070/"
     60 [Run]
     61 ;修改tomcat配置文件
     62 Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\tomcat6.0\conf\server.xml'),'/Server/Service/Connector','port','7070')
     63 ;修改web數據庫鏈接配置文件
     64 Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\tomcat6.0\webapps\ROOT\META-INF\Context.xml'),'/Context/Resource','password','123456')
     65 Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\tomcat6.0\webapps\ROOT\META-INF\Context.xml'),'/Context/Resource','url','jdbc:mysql://127.0.0.1:3308/abc?characterEncoding=UTF-8')
     66 ;修改FTP配置文件
     67 Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\FtpServer\FileZilla Server.xml'),'/FileZillaServer/Users/User','Name','admin')
     68 Filename:"{app}\loading.bat";AfterInstall:ConfigXml2(ExpandConstant('{app}\FtpServer\FileZilla Server.xml'),'/FileZillaServer/Users/User/Option[0]','e10adc3949ba59abbe56e057f20f883e')
     69 Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\FtpServer\FileZilla Server.xml'),'/FileZillaServer/Users/User/Permissions/Permission','Dir',ExpandConstant('{app}\tomcat6.0\webapps\ROOT\SystemFile'))
     70 ;修改服務配置文件
     71 Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\Sdk\abc.config'),'/configuration/appSettings/add[1]','value','127.0.0.1')
     72 Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\Sdk\abc.config'),'/configuration/appSettings/add[2]','value','5556')
     73 Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\Sdk\abc.config'),'/configuration/appSettings/add[3]','value','127.0.0.1')
     74 Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\Sdk\abc.config'),'/configuration/appSettings/add[4]','value','7070')
     75 Filename:"{app}\install.bat";Description:"正在啓動或配置相關程序";
     76 [UninstallRun]
     77 Filename:"{app}\uninstall.bat";
     78 [UninstallDelete]
     79 Type:filesandordirs;Name:"{app}\Server" 
     80 Type:filesandordirs;Name:"{app}\MySql5.5"
     81 Type:filesandordirs;Name:"{app}\Sdk"
     82 Type:filesandordirs;Name:"{app}\tomcat6.0"
     83 Type:files;Name:"{app}\InstallUtil.InstallLog"
     84 [Code]
     85 procedure ConfigXml2(xmlPath:String;xPath:String;innerText:String);
     86 var
     87     XMLDocument,XMLRoot,XMLNode:Variant;
     88 begin
     89     try
     90     XMLDocument := CreateOleObject('MSXML2.DOMDocument');
     91     XMLDocument.async := False;
     92     XMLDocument.resolveExternals := False;
     93     XMLDocument.load(xmlPath);
     94     XMLRoot := XMLDocument.documentElement;
     95 
     96     XMLNode:=XMLRoot.SelectSingleNode(xPath);
     97     XMLNode.Text:=innerText;
     98     XMLDocument.Save(xmlPath);
     99     except
    100     MsgBox('xml error', mbInformation, mb_Ok);
    101     end;
    102 end; 
    103 procedure ConfigXml(xmlPath:String;xPath:String;attrName:String;attrValue:String);
    104 var
    105     XMLDocument,XMLRoot,XMLNode:Variant;
    106 begin
    107     try
    108     XMLDocument := CreateOleObject('MSXML2.DOMDocument');
    109     XMLDocument.async := False;
    110     XMLDocument.resolveExternals := False;
    111     XMLDocument.load(xmlPath);
    112     XMLRoot := XMLDocument.documentElement;
    113 
    114     XMLNode:=XMLRoot.SelectSingleNode(xPath);
    115     XMLNode.Attributes.GetNamedItem(attrName).Value:=attrValue;
    116     XMLDocument.Save(xmlPath);
    117     except
    118     MsgBox('xml error', mbInformation, mb_Ok);
    119     end;
    120 end;                                                                                       
  • 打包腳本調用的bat安裝腳本
    @echo off 
    title 運維繫統正在安裝中,請不要手動關閉
    color 0a
    echo jdk 環境變量
    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v JAVA_HOME /t REG_EXPAND_SZ /d "%cd%\jdk1.6" /f
    echo tomcat 環境變量
    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v CATALINA_HOME /t REG_EXPAND_SZ /d "%cd%\tomcat6.0" /f
    echo 系統環境變量
    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "PATH" /d "%PATH%;%cd%\jdk1.6\bin;%cd%\tomcat6.0\bin;" /f
    echo 啓動mysql並更新密碼
    "%cd%\MySql5.5\bin\mysqld.exe" --install "abcMysql" --defaults-file="%cd%\MySql5.5\my.ini"
    net start abcMysql
    sc config abcMysql start=auto
    ping -n 30 127.1>nul
    "%cd%\MySql5.5\bin\mysql.exe" --defaults-file="%cd%\MySql5.5\my.ini" -u root -e "UPDATE mysql.user SET Password=old_password('123456') WHERE User='root' or User='';"
    "%cd%\MySql5.5\bin\mysql.exe" --defaults-file="%cd%\MySql5.5\my.ini" -u root -e "FLUSH PRIVILEGES;"
    echo 初始化mysql數據庫
    "%cd%\MySql5.5\bin\mysql.exe"  -uroot -p123456 < "%cd%\tomcat6.0\webapps\ROOT\abc.sql"
    net stop abcMysql
    net start abcMysql
    echo 安裝ftp
    "%cd%\FtpServer\FileZilla server.exe" /install auto
    "%cd%\FtpServer\FileZilla server.exe" /start
    echo 安裝服務器
    sc create abcMessageService binpath= "%cd%\Server\Server.exe" displayname= "abcMessageService" start= auto 
    Net Start abcMessageService
    echo 啓動tomcat
    set JAVA_HOME=%cd%\jdk1.6
    set CATALINA_HOME=%cd%\tomcat6.0
    set CATALINA_BASE=%cd%\tomcat6.0
    cd .\tomcat6.0\bin
    call service.bat install
    sc config abcTomcat6 start=auto
    net start abcTomcat6
    cd ..\..\
    echo 安裝服務
    %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\installutil.exe "%cd%\Sdk\abc.exe"
    Net Start abcService
    sc config abcService start=auto
    exit
  • 打包腳本調用的bat卸載腳本
    @echo off
    title abc系統正在卸載中,請不要手動關閉
    color 0a
    echo 刪除環境變量
    reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v JAVA_HOME  /f   
    reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v CATALINA_HOME  /f   
    echo 中止並刪除tomcat
    net stop abcTomcat6
    cd .\tomcat6.0\bin
    call service.bat remove
    cd ..\..\
    echo 中止並刪除mysql
    net stop abcMysql
    sc delete abcMysql
    echo 中止並卸載FTP
    "%cd%\FtpServer\FileZilla server.exe" /stop
    "%cd%\FtpServer\FileZilla server.exe" /uninstall
    echo 卸載註冊服務器
    Net Stop abcMessageService
    sc delete abcMessageService
    echo 卸載運維服務
    Net Stop abcService
    %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\installutil.exe -u "%cd%\Sdk\abc.exe"
    sc delete abcService
    exit
  • 打包腳本調用的bat等待腳本
    @echo off 
    echo pause;
  • 其餘相關
    1.建議把要打包的內容都放在同一個目錄下面
    2.本身新建一個ie網站快捷方式,用記事本打開之後修改爲本身app的鏈接地址
    3.這個ftp是使用的FileZilla,配置文件中的密碼是標準md5加密
    4.代碼裏面的東西能夠根據我的項目的實際狀況作適當的調整。
  • 竟然第一篇文章是寫的打包相關,我也是醉了,只是但願可以幫助到一些須要的人,高手請飄過~
相關文章
相關標籤/搜索