zoukankan      html  css  js  c++  java
  • 使用Inno Setup 打包jdk、mysql、tomcat、webapp等为一个exe安装包

      之前一直都没涉及到打包安装方面的东西,都是另一个同事负责的,使用的工具(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服务安装、环境变量配置、数据库初始化等,唯独缺少注册表和防火墙配置(%>_<%)
    • 打包脚本
        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:"Sourceapache-tomcat-6.0.41*";DestDir:"{app}	omcat6.0";Flags:igNoreversion recursesubdirs createallsubdirs
       30 ;拷贝jdk
       31 Source:"Sourcejdk1.6.0_43*";DestDir:"{app}jdk1.6";Flags:igNoreversion recursesubdirs createallsubdirs
       32 ;拷贝mysql
       33 Source:"SourceMySql5.5*";DestDir:"{app}MySql5.5";Flags:igNoreversion recursesubdirs createallsubdirs
       34 ;拷贝源代码
       35 Source:"Sourceabc*";DestDir:"{app}	omcat6.0webappsROOT";Flags:igNoreversion recursesubdirs createallsubdirs
       36 ;拷贝sdk
       37 Source:"SourceSdk*";DestDir:"{app}Sdk";Flags:igNoreversion recursesubdirs createallsubdirs
       38 ;拷贝服务器
       39 Source:"SourceServer*";DestDir:"{app}Server";Flags:igNoreversion recursesubdirs createallsubdirs
       40 ;拷贝ftp
       41 Source:"SourceFtpServer*";DestDir:"{app}FtpServer";Flags:igNoreversion recursesubdirs createallsubdirs
       42 ;拷贝bat
       43 Source:"Source*";DestDir:"{app}";
       44 ;拷贝桌面快捷方式
       45 Source:"Sourcexx系统.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.5my.ini";Section:"mysqld";Key:"basedir"; String:"{app}MySql5.5"
       54 Filename:"{app}MySql5.5my.ini";Section:"mysqld";Key:"datadir"; String:"{app}MySql5.5data"
       55 Filename:"{app}MySql5.5my.ini";Section:"mysqld";Key:"port"; String:"3308"
       56 Filename:"{app}MySql5.5my.ini";Section:"client";Key:"port"; String:"3308"
       57 ;修改服务器配置文件
       58 Filename:"{app}Serverinit.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}	omcat6.0confserver.xml'),'/Server/Service/Connector','port','7070')
       63 ;修改web数据库连接配置文件
       64 Filename:"{app}loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}	omcat6.0webappsROOTMETA-INFContext.xml'),'/Context/Resource','password','123456')
       65 Filename:"{app}loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}	omcat6.0webappsROOTMETA-INFContext.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}FtpServerFileZilla Server.xml'),'/FileZillaServer/Users/User','Name','admin')
       68 Filename:"{app}loading.bat";AfterInstall:ConfigXml2(ExpandConstant('{app}FtpServerFileZilla Server.xml'),'/FileZillaServer/Users/User/Option[0]','e10adc3949ba59abbe56e057f20f883e')
       69 Filename:"{app}loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}FtpServerFileZilla Server.xml'),'/FileZillaServer/Users/User/Permissions/Permission','Dir',ExpandConstant('{app}	omcat6.0webappsROOTSystemFile'))
       70 ;修改服务配置文件
       71 Filename:"{app}loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}Sdkabc.config'),'/configuration/appSettings/add[1]','value','127.0.0.1')
       72 Filename:"{app}loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}Sdkabc.config'),'/configuration/appSettings/add[2]','value','5556')
       73 Filename:"{app}loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}Sdkabc.config'),'/configuration/appSettings/add[3]','value','127.0.0.1')
       74 Filename:"{app}loading.bat";AfterInstall:ConfigXml(ExpandConstant('{app}Sdkabc.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}	omcat6.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_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v JAVA_HOME /t REG_EXPAND_SZ /d "%cd%jdk1.6" /f
      echo tomcat 环境变量
      reg add "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v CATALINA_HOME /t REG_EXPAND_SZ /d "%cd%	omcat6.0" /f
      echo 系统环境变量
      reg add "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v "PATH" /d "%PATH%;%cd%jdk1.6in;%cd%	omcat6.0in;" /f
      echo 启动mysql并更新密码
      "%cd%MySql5.5inmysqld.exe" --install "abcMysql" --defaults-file="%cd%MySql5.5my.ini"
      net start abcMysql
      sc config abcMysql start=auto
      ping -n 30 127.1>nul
      "%cd%MySql5.5inmysql.exe" --defaults-file="%cd%MySql5.5my.ini" -u root -e "UPDATE mysql.user SET Password=old_password('123456') WHERE User='root' or User='';"
      "%cd%MySql5.5inmysql.exe" --defaults-file="%cd%MySql5.5my.ini" -u root -e "FLUSH PRIVILEGES;"
      echo 初始化mysql数据库
      "%cd%MySql5.5inmysql.exe"  -uroot -p123456 < "%cd%	omcat6.0webappsROOTabc.sql"
      net stop abcMysql
      net start abcMysql
      echo 安装ftp
      "%cd%FtpServerFileZilla server.exe" /install auto
      "%cd%FtpServerFileZilla server.exe" /start
      echo 安装服务器
      sc create abcMessageService binpath= "%cd%ServerServer.exe" displayname= "abcMessageService" start= auto 
      Net Start abcMessageService
      echo 启动tomcat
      set JAVA_HOME=%cd%jdk1.6
      set CATALINA_HOME=%cd%	omcat6.0
      set CATALINA_BASE=%cd%	omcat6.0
      cd .	omcat6.0in
      call service.bat install
      sc config abcTomcat6 start=auto
      net start abcTomcat6
      cd ....
      echo 安装服务
      %SystemRoot%Microsoft.NETFrameworkv2.0.50727installutil.exe "%cd%Sdkabc.exe"
      Net Start abcService
      sc config abcService start=auto
      exit
    • 打包脚本调用的bat卸载脚本
      @echo off
      title abc系统正在卸载中,请不要手动关闭
      color 0a
      echo 删除环境变量
      reg delete "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v JAVA_HOME  /f   
      reg delete "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v CATALINA_HOME  /f   
      echo 停止并删除tomcat
      net stop abcTomcat6
      cd .	omcat6.0in
      call service.bat remove
      cd ....
      echo 停止并删除mysql
      net stop abcMysql
      sc delete abcMysql
      echo 停止并卸载FTP
      "%cd%FtpServerFileZilla server.exe" /stop
      "%cd%FtpServerFileZilla server.exe" /uninstall
      echo 卸载注册服务器
      Net Stop abcMessageService
      sc delete abcMessageService
      echo 卸载运维服务
      Net Stop abcService
      %SystemRoot%Microsoft.NETFrameworkv2.0.50727installutil.exe -u "%cd%Sdkabc.exe"
      sc delete abcService
      exit
    • 打包脚本调用的bat等待脚本
      @echo off 
      echo pause;
    • 其他相关
      1.建议把要打包的内容都放在同一个目录下面
      2.自己新建一个ie网站快捷方式,用记事本打开以后修改成自己app的连接地址
      3.这个ftp是使用的FileZilla,配置文件中的密码是标准md5加密
      4.代码里面的东西可以根据个人项目的实际情况做适当的调整。
    • 居然第一篇文章是写的打包相关,我也是醉了,只是希望能够帮助到一些需要的人,高手请飘过~
    欢迎转载,请保留著作信息
  • 相关阅读:
    Javadoc注释的用法
    Java 和 Android系统环境变量设置
    [转载]Android开发新浪微博客户端 完整攻略 [新手必读]
    eclipse中Android程序字符编码不统一的解决方案
    用word2007写blog时表格的显示效果
    解决Vista中的文件关联图标问题。
    用word2007在博客园发布带图片的blog
    在c++中使用gotoxy
    动态多线程任务管理
    几个视频切割工具
  • 原文地址:https://www.cnblogs.com/dehai168/p/4512484.html
Copyright © 2011-2022 走看看