之前一直都没涉及到打包安装方面的东西,都是另一个同事负责的,使用的工具(installshield)也比较高大上一点,可是后来他离职以后接受的同事也只能是在这个基础上做个简单的配置,然后打包,可是现在做的项目和原来的完全不一样以后就不能使用之前的了,只能是自己硬着头皮来弄个比较简单快捷的了。

  切入正题,如标题所述使用inno setup来打包一个java web 相关的内容为一个exe,.net web类似,这个工具可以在网上直接找到下载,有汉化版的,并且里面也有帮助手册可以参考。把里面的一些敏感信息已经做了替代,这些都是可以根据你自己情况来修改的。下面直接上干货。

  • 打包和发布的内容
    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服务安装、环境变量配置、数据库初始化等,唯独缺少注册表和防火墙配置(%>_<%)
  • 打包脚本
     ; 脚本由 Inno Setup 脚本向导 生成!
    ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "abc"
    #define MyAppVersion "1.0"
    #define MyAppPublisher "aaa"
    #define MyAppURL "http://www.abc.com/" [Setup]
    ; 注: AppId的值为单独标识该应用程序。
    ; 不要为其他安装程序使用相同的AppId值。
    ; (生成新的GUID,点击 工具|在IDE中生成GUID。)
    AppId={{9E044575-9CD9-4751-B0BE-F6758BA94548}
    AppName={#MyAppName}
    AppVersion={#MyAppVersion}
    ;AppVerName={#MyAppName} {#MyAppVersion}
    AppPublisher={#MyAppPublisher}
    AppPublisherURL={#MyAppURL}
    AppSupportURL={#MyAppURL}
    AppUpdatesURL={#MyAppURL}
    DefaultDirName={pf}\{#MyAppName}
    DefaultGroupName=XX管理软件(abc)
    AllowNoIcons=yes
    OutputBaseFilename=setup
    Compression=lzma
    SolidCompression=yes
    [Files]
    ;拷贝tomcat
    Source:"Source\apache-tomcat-6.0.\*";DestDir:"{app}\tomcat6.";Flags:igNoreversion recursesubdirs createallsubdirs
    ;拷贝jdk
    Source:"Source\jdk1.6.0_\*";DestDir:"{app}\jdk1.";Flags:igNoreversion recursesubdirs createallsubdirs
    ;拷贝mysql
    Source:"Source\MySql5.\*";DestDir:"{app}\MySql5.";Flags:igNoreversion recursesubdirs createallsubdirs
    ;拷贝源代码
    Source:"Source\abc\*";DestDir:"{app}\tomcat6.\webapps\ROOT";Flags:igNoreversion recursesubdirs createallsubdirs
    ;拷贝sdk
    Source:"Source\Sdk\*";DestDir:"{app}\Sdk";Flags:igNoreversion recursesubdirs createallsubdirs
    ;拷贝服务器
    Source:"Source\Server\*";DestDir:"{app}\Server";Flags:igNoreversion recursesubdirs createallsubdirs
    ;拷贝ftp
    Source:"Source\FtpServer\*";DestDir:"{app}\FtpServer";Flags:igNoreversion recursesubdirs createallsubdirs
    ;拷贝bat
    Source:"Source\*";DestDir:"{app}\";
    ;拷贝桌面快捷方式
    Source:"Source\xx系统.url";DestDir:"{userdesktop}\xx系统";
    [Languages]
    Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"
    [Icons]
    Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}"
    Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
    [INI]
    ;修改数据库配置文件
    Filename:"{app}\MySql5.\my.ini";Section:"mysqld";Key:"basedir"; String:"{app}\MySql5."
    Filename:"{app}\MySql5.\my.ini";Section:"mysqld";Key:"datadir"; String:"{app}\MySql5.\data"
    Filename:"{app}\MySql5.\my.ini";Section:"mysqld";Key:"port"; String:""
    Filename:"{app}\MySql5.\my.ini";Section:"client";Key:"port"; String:""
    ;修改服务器配置文件
    Filename:"{app}\Server\init.ini";Section:"RegAddr";Key:"port"; String:""
    Filename:"{userdesktop}\xx系统.url";Section:"InternetShortcut";Key:"URL"; String:"http://127.0.0.1:/"
    [Run]
    ;修改tomcat配置文件
    Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\tomcat6.0\conf\server.xml'),'/Server/Service/Connector','port','')
    ;修改web数据库连接配置文件
    Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\tomcat6.0\webapps\ROOT\META-INF\Context.xml'),'/Context/Resource','password','')
    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')
    ;修改FTP配置文件
    Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\FtpServer\FileZilla Server.xml'),'/FileZillaServer/Users/User','Name','admin')
    Filename:"{app}\loading.bat";AfterInstall:ConfigXml2(ExpandConstant('{app}\FtpServer\FileZilla Server.xml'),'/FileZillaServer/Users/User/Option[0]','e10adc3949ba59abbe56e057f20f883e')
    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'))
    ;修改服务配置文件
    Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\Sdk\abc.config'),'/configuration/appSettings/add[1]','value','127.0.0.1')
    Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\Sdk\abc.config'),'/configuration/appSettings/add[2]','value','')
    Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\Sdk\abc.config'),'/configuration/appSettings/add[3]','value','127.0.0.1')
    Filename:"{app}\loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}\Sdk\abc.config'),'/configuration/appSettings/add[4]','value','')
    Filename:"{app}\install.bat";Description:"正在启动或配置相关程序";
    [UninstallRun]
    Filename:"{app}\uninstall.bat";
    [UninstallDelete]
    Type:filesandordirs;Name:"{app}\Server"
    Type:filesandordirs;Name:"{app}\MySql5."
    Type:filesandordirs;Name:"{app}\Sdk"
    Type:filesandordirs;Name:"{app}\tomcat6."
    Type:files;Name:"{app}\InstallUtil.InstallLog"
    [Code]
    procedure ConfigXml2(xmlPath:String;xPath:String;innerText:String);
    var
    XMLDocument,XMLRoot,XMLNode:Variant;
    begin
    try
    XMLDocument := CreateOleObject('MSXML2.DOMDocument');
    XMLDocument.async := False;
    XMLDocument.resolveExternals := False;
    XMLDocument.load(xmlPath);
    XMLRoot := XMLDocument.documentElement; XMLNode:=XMLRoot.SelectSingleNode(xPath);
    XMLNode.Text:=innerText;
    XMLDocument.Save(xmlPath);
    except
    MsgBox('xml error', mbInformation, mb_Ok);
    end;
    end;
    procedure ConfigXml(xmlPath:String;xPath:String;attrName:String;attrValue:String);
    var
    XMLDocument,XMLRoot,XMLNode:Variant;
    begin
    try
    XMLDocument := CreateOleObject('MSXML2.DOMDocument');
    XMLDocument.async := False;
    XMLDocument.resolveExternals := False;
    XMLDocument.load(xmlPath);
    XMLRoot := XMLDocument.documentElement; XMLNode:=XMLRoot.SelectSingleNode(xPath);
    XMLNode.Attributes.GetNamedItem(attrName).Value:=attrValue;
    XMLDocument.Save(xmlPath);
    except
    MsgBox('xml error', mbInformation, mb_Ok);
    end;
    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 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.
    set CATALINA_HOME=%cd%\tomcat6.
    set CATALINA_BASE=%cd%\tomcat6.
    cd .\tomcat6.\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.\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.代码里面的东西可以根据个人项目的实际情况做适当的调整。
  • 居然第一篇文章是写的打包相关,我也是醉了,只是希望能够帮助到一些需要的人,高手请飘过~

使用Inno Setup 打包jdk、mysql、tomcat、webapp等为一个exe安装包的更多相关文章

  1. 使用Inno Setup 打包jdk、mysql、tomcat、webapp等为一个exe安装包(转)

    之前一直都没涉及到打包安装方面的东西,都是另一个同事负责的,使用的工具(installshield)也比较高大上一点,可是后来他离职以后接受的同事也只能是在这个基础上做个简单的配置,然后打包,可是现在 ...

  2. Qt之程序发布以及打包成exe安装包

    一.简述 Qt项目开发完成之后,需要打包发布程序,而因为用户电脑上没有Qt配置环境,所以需要将release生成的exe文件和所依赖的dll文件复制到一个文件夹中,然后再用 Inno Setup打包工 ...

  3. Qt 程序发布以及打包成exe安装包

    一.简述 Qt 项目开发完成之后,需要打包发布程序,而因为用户电脑上没有 Qt 配置环境,所以需要将 release 生成的 exe 文件和所依赖的 dll 文件复制到一个文件夹中,然后再用 Inno ...

  4. NSIS打包electron程序为exe安装包

    在我的上一篇博客已经介绍了将electron程序生成一个exe可执行文件,但是这并不是最终能够发给用户用来安装的最终安装包,下面我们就介绍如何使用NISI将我们的应用程序打包成安装包: 上一篇博客我们 ...

  5. CentOS 5.5 Nginx+JDK+MySQL+Tomcat(jsp)成功安装案例

    在CentOS 5.5中安装Nginx+jdk+mysql+tomcat是非常容易的.只需yum安装环境包和nginx.解压安装jdk和tomcat.配置profile文件.server.xml和ng ...

  6. Inno Setup 打包工具总结

    Inno Setup 打包工具总结 分类: Install Setup 2013-02-02 15:44 2386人阅读 评论(0) 收藏 举报 最近打包用到了Inno setup,在这个过程中容易犯 ...

  7. 使用Inno Setup 打包.NET程序,并自动安装.Net Framework

    使用Inno Setup 打包.NET程序,并自动安装.Net Framework http://www.cnblogs.com/xiaogangqq123/archive/2012/03/19/24 ...

  8. (Inno setup打包)检测系统是否已安装程序,若已安装则弹出卸载提示的代码

    原文 http://bbs.itiankong.com/thread-30983-1-5.html 有6天没研究pascal代码了,昨天晚上突然来了灵感,终于解决了苦思冥想好几天没能解决的问题, 因此 ...

  9. Inno Setup打包的程序提升为管理员权限

    Inno Setup打包的程序在Win7 64位系统上安装,安装步骤最后一步若选中运行程序,会跳出一个错误提示框. 这是因为64位win7系统运行程序时需要管理员权限,而打包的文件并没有这个权限就试图 ...

随机推荐

  1. UVALive 3890 Most Distant Point from the Sea(凸包最大内接园)

    一个n个点的凸多边形,求多边形中离多边形边界最远的距离.实际上就是求凸包最大内接圆的半径. 利用半平面交求解,每次二分枚举半径d,然后将凸包每条边所代表的半平面沿其垂直单位法向量平移d,看所有平移后的 ...

  2. flex4 amcharts 删除水印

    package com.twobowl.component.manualTopo { import com.amcharts.AmPieChart; import com.amcharts.chart ...

  3. Connecting Docker for Cloud Services using SDN and Network Virtualization

     Abstract The explosive scale of container CPUs needs highly efficient network virtualization Chal ...

  4. java程序开发代写(QQ:928900200)

    条件:手机1.2都是安卓智能机,手机1开热点,手机2链接手机1,功能:A手机2通过刷手机网页,登陆手机1设定的页面并下载其手机的指定文件,B手机1控制手机2的流量,当通过的流量多的时候,停止流量的供应

  5. 【LeetCode】【Python解决问题的方法】Best Time to Buy and Sell Stock II

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  6. Java获得正则表达式

    t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,wid ...

  7. 3D MAX脚本教程1

    本文转载自http://jiurong995294.blog.163.com/blog/static/195133243201192531546490/ 方便以后须要时候使用 为什么要学习3D MAX ...

  8. swift排序算法和数据结构

    var arrayNumber: [Int] = [2, 4, 6, 7, 3, 8, 1] //冒泡排序 func maopao(var array: [Int]) -> [Int] { fo ...

  9. vmware 10 注冊码

    先安装VMware Workstation 10.0原版,然后用以下的随意一个VMware Workstation序列号注冊 1Y0LW-4WJ9N-LZ5G9-Z81QP-92PN7 JU052-F ...

  10. [LeetCode129]Sum Root to Leaf Numbers

    题目: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a nu ...