zoukankan      html  css  js  c++  java
  • jdk+tomcat+mysql+war打包整合成exe文件,Windows下一键安装

    一、准备

       1、下载免安装的mysql、tomcat、jdk(我用的是:官网下载的mysql-5.5.40、tomcat8.0、jdk1.8,都是64位的);

       2、下载Inno Setup 打包工具(我用的是:Inno Setup 5版);

       3、我在D盘建了个文件夹,命名为test ;

       4、把下载好的mysql-5.5.40、tomcat8.0一起复制到“D: est”下;  

       5、把下载好的jdk放在“D: estapache-tomcat-8.0.29in”下:

    二、打包的准备,写脚本

        1、mysql的准备

        1.1  因为我在官网下的mysql没有my.ini,所以我就上网找了个,然后修改里面的内容就行,放在“D: estmysql-5.5.40-winx64”下,以免出错:(标红的是我修改的,下文也是如此

     ========my.ini  start=========

    # MySQL Server Instance Configuration File

    # ----------------------------------------------------------------------

    # Generated by the MySQL Server Instance Configuration Wizard

    # Installation Instructions

    # ----------------------------------------------------------------------

    # On Linux you can copy this file to /etc/my.cnf to set global options,

    # mysql-data-dir/my.cnf to set server-specific options

    # (@localstatedir@ for this installation) or to

    # ~/.my.cnf to set user-specific options.

    # On Windows you should keep this file in the installation directory 

    # of your server (e.g. C:Program FilesMySQLMySQL Server X.Y). To

    # make sure the server reads the config file use the startup option 

    # "--defaults-file". 

    #

    # To run run the server from the command line, execute this in a 

    # command line shell, e.g.

    # mysqld --defaults-file="D: estmysql-5.5.40-winx64my.ini"

    #

    # To install the server as a Windows service manually, execute this in a 

    # command line shell, e.g.

    # mysqld --install MySQLXY --defaults-file="D: estmysql-5.5.40-winx64my.ini"

    #

    # And then execute this in a command line shell to start the server, e.g.

    # net start MySQLXY

    #

    # Guildlines for editing this file

    # ----------------------------------------------------------------------

    #

    # In this file, you can use all long options that the program supports.

    # If you want to know the options a program supports, start the program

    # with the "--help" option.

    #

    # More detailed information about the individual options can also be

    # found in the manual.

    #

    # CLIENT SECTION

    # ----------------------------------------------------------------------

    #

    # The following options will be read by MySQL client applications.

    # Note that only client applications shipped by MySQL are guaranteed

    # to read this section. If you want your own MySQL client program to

    # honor these values, you need to specify it as an option during the

    # MySQL client library initialization.

    #

    [client]

    port=3306

    [mysql]

    default-character-set=utf8

    # SERVER SECTION

    # ----------------------------------------------------------------------

    #

    # The following options will be read by the MySQL Server. Make sure that

    # you have installed the server correctly (see above) so it reads this 

    # file.

    [mysqld]

    # The TCP/IP Port the MySQL Server will listen on

    port=3306

    #Path to installation directory. All paths are usually resolved relative to this.

    basedir="D:/test/mysql-5.5.40-winx64"

    #Path to the database root

    datadir="D:/test/mysql-5.5.40-winx64/data/"

    # The default character set that will be used when a new schema or table is

    # created and no character set is defined

    character-set-server=utf8

    # The default storage engine that will be used when create new tables when

    default-storage-engine=INNODB

    # Set the SQL mode to strict

    sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

    # The maximum amount of concurrent sessions the MySQL server will

    # allow. One of these connections will be reserved for a user with

    # SUPER privileges to allow the administrator to login even if the

    # connection limit has been reached.

    max_connections=100

    # Query cache is used to cache SELECT results and later return them

    # without actual executing the same query once again. Having the query

    # cache enabled may result in significant speed improvements, if your

    # have a lot of identical queries and rarely changing tables. See the

    # "Qcache_lowmem_prunes" status variable to check if the current value

    # is high enough for your load.

    # Note: In case your tables change very often or if your queries are

    # textually different every time, the query cache may result in a

    # slowdown instead of a performance improvement.

    query_cache_size=32M

    # The number of open tables for all threads. Increasing this value

    # increases the number of file descriptors that mysqld requires.

    # Therefore you have to make sure to set the amount of open files

    # allowed to at least 4096 in the variable "open-files-limit" in

    # section [mysqld_safe]

    table_open_cache=256

    # Maximum size for internal (in-memory) temporary tables. If a table

    # grows larger than this value, it is automatically converted to disk

    # based table This limitation is for a single table. There can be many

    # of them.

    tmp_table_size=35M

    # How many threads we should keep in a cache for reuse. When a client

    # disconnects, the client's threads are put in the cache if there aren't

    # more than thread_cache_size threads from before.  This greatly reduces

    # the amount of thread creations needed if you have a lot of new

    # connections. (Normally this doesn't give a notable performance

    # improvement if you have a good thread implementation.)

    thread_cache_size=8

    #*** MyISAM Specific options

    # The maximum size of the temporary file MySQL is allowed to use while

    # recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.

    # If the file-size would be bigger than this, the index will be created

    # through the key cache (which is slower).

    myisam_max_sort_file_size=100G

    # If the temporary file used for fast index creation would be bigger

    # than using the key cache by the amount specified here, then prefer the

    # key cache method.  This is mainly used to force long character keys in

    # large tables to use the slower key cache method to create the index.

    myisam_sort_buffer_size=69M

    # Size of the Key Buffer, used to cache index blocks for MyISAM tables.

    # Do not set it larger than 30% of your available memory, as some memory

    # is also required by the OS to cache rows. Even if you're not using

    # MyISAM tables, you should still set it to 8-64M as it will also be

    # used for internal temporary disk tables.

    key_buffer_size=50M

    # Size of the buffer used for doing full table scans of MyISAM tables.

    # Allocated per thread, if a full scan is needed.

    read_buffer_size=64K

    read_rnd_buffer_size=256K

    # This buffer is allocated when MySQL needs to rebuild the index in

    # REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE

    # into an empty table. It is allocated per thread so be careful with

    # large settings.

    sort_buffer_size=256K

    #*** INNODB Specific options ***

    # Use this option if you have a MySQL server with InnoDB support enabled

    # but you do not plan to use it. This will save memory and disk space

    # and speed up some things.

    #skip-innodb

    # Additional memory pool that is used by InnoDB to store metadata

    # information.  If InnoDB requires more memory for this purpose it will

    # start to allocate it from the OS.  As this is fast enough on most

    # recent operating systems, you normally do not need to change this

    # value. SHOW INNODB STATUS will display the current amount used.

    #innodb_additional_mem_pool_size=14M

    # If set to 1, InnoDB will flush (fsync) the transaction logs to the

    # disk at each commit, which offers full ACID behavior. If you are

    # willing to compromise this safety, and you are running small

    # transactions, you may set this to 0 or 2 to reduce disk I/O to the

    # logs. Value 0 means that the log is only written to the log file and

    # the log file flushed to disk approximately once per second. Value 2

    # means the log is written to the log file at each commit, but the log

    # file is only flushed to disk approximately once per second.

    innodb_flush_log_at_trx_commit=1

    # The size of the buffer InnoDB uses for buffering log data. As soon as

    # it is full, InnoDB will have to flush it to disk. As it is flushed

    # once per second anyway, it does not make sense to have it very large

    # (even with long transactions).

    innodb_log_buffer_size=1M

    # InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and

    # row data. The bigger you set this the less disk I/O is needed to

    # access data in tables. On a dedicated database server you may set this

    # parameter up to 80% of the machine physical memory size. Do not set it

    # too large, though, because competition of the physical memory may

    # cause paging in the operating system.  Note that on 32bit systems you

    # might be limited to 2-3.5G of user level memory per process, so do not

    # set it too high.

    innodb_buffer_pool_size=96M

    # Size of each log file in a log group. You should set the combined size

    # of log files to about 25%-100% of your buffer pool size to avoid

    # unneeded buffer pool flush activity on log file overwrite. However,

    # note that a larger logfile size will increase the time needed for the

    # recovery process.

    innodb_log_file_size=20M

    # Number of threads allowed inside the InnoDB kernel. The optimal value

    # depends highly on the application, hardware as well as the OS

    # scheduler properties. A too high value may lead to thread thrashing.

    innodb_thread_concurrency=18

    ========my.ini  end=========

    1.2  把创建数据库、表、用户数据的sql放在“D: estmysql-5.5.40-winx64data“下:

    1.3 写mysql的批处理脚本,放在“D: estmysql-5.5.40-winx64in”下

    ========mysql_ini.bat  start=========

    cd /d %~dp0 

    "%cd%mysqld.exe" --initialize-insecure --user=mysql --console

    echo -----mysql init succee-----

    pause;

    mysqld install mysql --defaults-file="D: estmysql-5.5.40-winx64my.ini"

    echo -----mysql service install succee-----

    pause;

    net start mysql

    sc config mysql start=auto 

    net stop mysql

    net start mysql

    echo 安装完毕 

    pause;

    "%cd%mysqladmin" -u root password root

    echo 修改密码完毕 

    pause;

    cd .. 

    "%cd%inmysql.exe" -uroot -proot < "%cd%datassm_work.sql

    echo 建表完毕 

    pause;

    echo 建立新用户完毕

    =======mysql_ini.bat  end========

    2、jdk的准备

    2.1 写jdk的批处理脚本,放在“D: estapache-tomcat-8.0.29inJavajdk1.8.0_151in”下(注意路径哦

    ========autoInstallJDK.bat  start========

    @echo off 

    echo

    cd ..

    echo  "%~dp0"

    echo "%cd%"

    set jdkpath=%cd%apache-tomcat-8.0.29inJavajdk1.8.0_151

    echo %jdkpath%

    setx JAVA_HOME  "%jdkpath%"  -m

    setx CLASSPATH  ".;%%JAVA_HOME%%lib ools.jar;%%JAVA_HOME%%libdt.jar" -m

    echo %Path%

    echo %Path%|find /i "%java_home%" && set IsNull=true || set IsNull=false

    echo %IsNull%

    if not %IsNull%==true (

    reg add "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v Path /t REG_SZ /d "%Path%;%%JAVA_HOME%%in;%%JAVA_HOME%%jrein" /f

    setx Path "%%JAVA_HOME%%in;%Path%"

    )

    exit

    ========autoInstallJDK.bat  start========

    3、tomcat的准备

    3.1 写tomcat的批处理脚本,放在“D: estapache-tomcat-8.0.29in”下:

    ========启动服务.bat  start========

    echo

    call "%~dp0%service.bat" install tomcat8

    echo

    sc config tomcat8 start= auto 

    sc start tomcat8

    rem 下面两句是设置到服务里自动启动的

    wmic service where name="tomcat8" changestartmode "automatic"

    wmic service where name="tomcat8" startservice

    exit

    ========启动服务.bat  end==========

     

    3.2 把打包好的war包 直接复制 放在“D: estapache-tomcat-8.0.29webapps”下:

     

    好了,目前脚本什么的都弄完了,就开始整合.exe文件。

    三、使用Inno Setup工具制作.exe文件

        1、在“D: est”下创建一个.iss后缀的文件,然后复制我下面给出的文件内容,修改并执行它,工具就会在当前目录创建一个名为“Output”文件夹,里面存有一个.exe的安装包。   

    [Setup]区域的命名和路径之类的我就不详说了

    ========now.iss  start========

    ; 脚本由 Inno Setup 脚本向导 生成!

    [Setup]

    ; 注: AppId的值为单独标识该应用程序。

    ; 不要为其他安装程序使用相同的AppId值。

    ; (生成新的GUID,点击 工具|在IDE中生成GUID。)

    AppId={{9E044575-9CD9-4751-B0BE-F6758BA94548}

    AppName=Test

    AppVersion=V0.01

    AppVerName=TestServer V0.01

    AppPublisher=TestTechnology

    AppPublisherURL=http://www.baidu.com/

    AppSupportURL=http://www.baidu.com/

    AppUpdatesURL=http://www.baidu.com/

    DefaultDirName={pf}Test

    DefaultGroupName=TestSoftWare

    AllowNoIcons=yes

    OutputBaseFilename=Test

    Compression=lzma

    SolidCompression=yes

    [Files]

    ;拷贝tomcat

    Source:"D: estapache-tomcat-8.0.29*";DestDir:"{app}apache-tomcat-8.0.29";Flags:igNoreversion recursesubdirs createallsubdirs

    ;拷贝mysql

    Source:"D: estmysql-5.5.40-winx64*";DestDir:"{app}mysql-5.5.40-winx64";Flags:igNoreversion recursesubdirs createallsubdirs

    [Languages]

    Name: "english"; MessagesFile: "compiler:Default.isl"

    [Icons]

    Name: "{group}{cm:UninstallProgram,学生管理系统}"; Filename: "{uninstallexe}"

    Name: "{commondesktop}学生管理系统"; Filename: http://localhost:8080/SSMWork/html/login.html 

    [INI]

    ;修改数据库配置文件

    Filename:"{app}mysql-5.5.40-winx64my.ini";Section:"mysqld";Key:"basedir"; String:"{app}mysql-5.5.40-winx64"

    Filename:"{app}mysql-5.5.40-winx64my.ini";Section:"mysqld";Key:"datadir"; String:"{app}mysql-5.5.40-winx64data"

    Filename:"{app}mysql-5.5.40-winx64my.ini";Section:"mysqld";Key:"port"; String:"3306"

    Filename:"{app}mysql-5.5.40-winx64my.ini";Section:"client";Key:"port"; String:"3306"

    [Run]

    Filename: "{app}apache-tomcat-8.0.29inJavajdk1.8.0_151inautoInstallJDK.bat";

    Filename: "{app}mysql-5.5.40-winx64inmysql_init.bat";

    Filename: "{app}apache-tomcat-8.0.29in启动服务.bat";

    [UninstallDelete]

    Type:filesandordirs;Name:"{app}apache-tomcat-8.0.29"

    Type:filesandordirs;Name:"{app}mysql-5.5.40-winx64"

    ========now.iss  end========

    **mysql、tomcat、jdk、war包整合全部结束,共需要创建、修改、复制的有 8 个文件。**

    jdk:autoInstallJDK.bat

    tomcat:SSMWork.war,启动服务.bat,service.bat

    Inno setup:now.iss

    mysql:my.ini,mysql_init.bat,ssm_work.sql

    我在我自己的vmware虚拟机和笔记本电脑都成功安装了!这两个都是全新的无配置环境的系统

     

    总结:

          打包过程经历了几天,导致这么久的主要问题是:1、网上的教程有些不全面,不够细致;2、还有自己的一些粗心大意,有些细节没看全,急躁,jishi成功的打包了exe文件,但安装就会出现问题。所以还是不管做什么事情,即使再简单,还是需要一丝不苟的对待它。   

         可能会遇到的问题,如何去解决:

          1、安装包没安装成功,根据弹出的错误提示,去看是从哪里出错,然后再到那一个点来解决它;

          2、安装成功后启动程序出现mysql、tomcat或者jdk有问题,可以根据日志去找找失败的原因,英文不懂可以找翻译软件翻译,这很关键。

           

    以上就是整合所需的东西和过程,算是比较详细了,希望可以帮到有需要的人。第一次写文章可能有些问题,自己没有发现到,如有疑问可以提出问题互相交流,谢谢。

    转载博客:

    https://blog.csdn.net/qq_33240866/article/details/80066541

  • 相关阅读:
    Oracle基础 (十二)数学函数
    Oracle基础 (十一)字符串函数
    Oracle基础(十) DML数据操作
    Oracle 常用命令大全
    Oracle 常用的SQL语法和数据对象
    Server.MapPath()
    登陆sharepoint的主页,提示:文件存在(异常来自 HRESULT:0x80070050)
    如何查看电脑的开机时间
    SQL 2008登录的域账户与数据库服务器不再同一个域的 处理方法
    发布MVC项目到服务器上时候遇到的 模块 DirectoryListingModule 通知 ExecuteRequestHandler 处理程序 StaticFile 错误代码 0x00000000
  • 原文地址:https://www.cnblogs.com/IT-TOP/p/10551805.html
Copyright © 2011-2022 走看看