一、準備
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:\test”下;
5、把下載下傳好的jdk放在“D:\test\apache-tomcat-8.0.29\bin”下:
jdk+tomcat+mysql+war打包整合成exe檔案,Windows下一鍵安裝 二、打包的準備,寫腳本
1、mysql的準備
1.1 因為我在官網下的mysql沒有my.ini,是以我就上網找了個,然後修改裡面的内容就行,放在“D:\test\mysql-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
#(@lo[email protected] 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 Files\MySQL\MySQL 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:\test\mysql-5.5.40-winx64\my.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:\test\mysql-5.5.40-winx64\my.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=
jdk+tomcat+mysql+war打包整合成exe檔案,Windows下一鍵安裝 1.2 把建立資料庫、表、使用者資料的sql放在“D:\test\mysql-5.5.40-winx64\data“下:
1.3 寫mysql的批處理腳本,放在“D:\test\mysql-5.5.40-winx64\bin”下
jdk+tomcat+mysql+war打包整合成exe檔案,Windows下一鍵安裝 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:\test\mysql-5.5.40-winx64\my.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%\bin\mysql.exe” -uroot -proot %cd%\data\ssm_work.sql"
echo 建表完畢
pause;
echo 建立新使用者完畢
=mysql_ini.bat end==
jdk+tomcat+mysql+war打包整合成exe檔案,Windows下一鍵安裝 2、jdk的準備
2.1 寫jdk的批處理腳本,放在“D:\test\apache-tomcat-8.0.29\bin\Java\jdk1.8.0_151\bin”下
autoInstallJDK.bat start
@echo off
echo
cd …
echo “%~dp0”
echo “%cd%”
set jdkpath=%cd%\apache-tomcat-8.0.29\bin\Java\jdk1.8.0_151
echo %jdkpath%
setx JAVA_HOME “%jdkpath%” -m
setx CLASSPATH “.;%%JAVA_HOME%%\lib\tools.jar;%%JAVA_HOME%%\lib\dt.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_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” /v Path /t REG_SZ /d “%Path%;%%JAVA_HOME%%\bin;%%JAVA_HOME%%\jre\bin” /f
setx Path “%%JAVA_HOME%%\bin;%Path%”
)
exit
autoInstallJDK.bat start
jdk+tomcat+mysql+war打包整合成exe檔案,Windows下一鍵安裝 3、tomcat的準備
3.1 修改tomcat的service.bat檔案,因為這個檔案要配置tomcat8w.exe檔案的java裡的jvm
jdk+tomcat+mysql+war打包整合成exe檔案,Windows下一鍵安裝 ,如果不配置好服務裡的tomcat是無法啟動的,啟動就會報。而且tomcat8w.exe也打不開,會出現
jdk+tomcat+mysql+war打包整合成exe檔案,Windows下一鍵安裝 這個錯誤。
因為有有删除的地方,不好标紅,是以最好還是下載下傳個beyond compare工具來與原來的檔案進行比較,很清楚顯示哪裡不一樣。
service.bat start
@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements. See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the “License”); you may not use this file except in compliance with
rem the License. You may obtain a copy of the License at
rem
rem distributed under the License is distributed on an “AS IS” BASIS,
rem http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem ---------------------------------------------------------------------------
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.
rem Service is installed using default settings.
rem NT Service Install/Uninstall script
rem
rem Options
rem install Install the service using Tomcat8 as service name.
rem remove Remove the service from the System.
rem
rem Guess CATALINA_HOME if not defined
rem name (optional) If the second argument is present it is considered
rem to be new service name
rem ---------------------------------------------------------------------------
setlocal
set “CURRENT_DIR=%cd%”
echo The tomcat8.exe was not found…
rem if not “%CATALINA_HOME%” == “” goto gotHome
set “CATALINA_HOME=%cd%”
if exist “%CATALINA_HOME%\bin\tomcat8.exe” goto okHome
rem CD to the upper dir
cd …
set “CATALINA_HOME=%cd%”
:gotHome
if exist “%CATALINA_HOME%\bin\tomcat8.exe” goto okHome
if not “%JRE_HOME%” == “” goto gotJreHome
echo The CATALINA_HOME environment variable is not defined correctly.
echo This environment variable is needed to run this program
goto end
:okHome
rem Make sure prerequisite environment variables are set
if not “%JAVA_HOME%” == “” goto gotJdkHome
set “JRE_HOME=%JAVA_HOME%\jre”
echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
echo Service will try to guess them from the registry.
goto okJavaHome
:gotJreHome
if not exist “%JRE_HOME%\bin\java.exe” goto noJavaHome
if not exist “%JRE_HOME%\bin\javaw.exe” goto noJavaHome
goto okJavaHome
:gotJdkHome
echo The JAVA_HOME environment variable is not defined correctly
if not exist “%JAVA_HOME%\jre\bin\java.exe” goto okJavaHome
if not exist “%JAVA_HOME%\jre\bin\javaw.exe” goto noJavaHome
if not exist “%JAVA_HOME%\bin\javac.exe” goto noJavaHome
if not “%JRE_HOME%” == “” goto okJavaHome
set “JRE_HOME=%JAVA_HOME%\jre”
goto okJavaHome
:noJavaHome
echo This environment variable is needed to run this program
shift
echo NB: JAVA_HOME should point to a JDK not a JRE
goto end
:okJavaHome
if not “%CATALINA_BASE%” == “” goto gotBase
set “CATALINA_BASE=%CATALINA_HOME%”
:gotBase
set “EXECUTABLE=%CATALINA_HOME%\bin\tomcat8.exe”
rem Set default Service name
set SERVICE_NAME=Tomcat8
set DISPLAYNAME=Apache Tomcat 8.0
if “x%1x” == “xx” goto doInstall
set SERVICE_CMD=%1
:displayUsage
if “x%1x” == “xx” goto checkServiceCmd
set SERVICE_NAME=%1
set DISPLAYNAME=Apache Tomcat 8.0 %1
shift
if “x%1x” == “xx” goto checkServiceCmd
echo Unknown parameter “%1”
goto displayUsage
:checkServiceCmd
if /i %SERVICE_CMD% == install goto doInstall
if /i %SERVICE_CMD% == remove goto doRemove
if /i %SERVICE_CMD% == uninstall goto doRemove
echo Unknown parameter “%SERVICE_CMD%”
echo.
echo The service ‘%SERVICE_NAME%’ has been removed
echo Usage: service.bat install/remove [service_name]
goto end
:doRemove
rem Remove the service
echo Removing the service ‘%SERVICE_NAME%’ …
echo Using CATALINA_BASE: “%CATALINA_BASE%”
“%EXECUTABLE%” //DS//%SERVICE_NAME% ^
–LogPath “%CATALINA_BASE%\logs”
if not errorlevel 1 goto removed
echo Failed removing ‘%SERVICE_NAME%’ service
goto end
:removed
goto end
:doInstall
set “JRE_HOME=%JAVA_HOME%\jre”
rem Install the service
echo Warning: Neither ‘server’ nor ‘client’ jvm.dll was found at JRE_HOME.
echo Installing the service ‘%SERVICE_NAME%’ …
echo Using CATALINA_HOME: “%CATALINA_HOME%”
echo Using CATALINA_BASE: “%CATALINA_BASE%”
echo Using JAVA_HOME: “%JAVA_HOME%”
echo Using JRE_HOME: “%JRE_HOME%”
rem Try to use the server jvm
rem set “JVM=%JRE_HOME%\bin\server\jvm.dll”
rem if exist “%JVM%” goto foundJvm
rem Try to use the client jvm
set “JVM=%JRE_HOME%\bin\client\jvm.dll”
if exist “%JVM%” goto foundJvm
set JVM="%JAVA_HOME%\jre\bin\client\jvm.dll"
–StdOutput auto ^
:foundJvm
echo Using JVM: “%JVM%”
set “CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar”
if not “%CATALINA_HOME%” == “%CATALINA_BASE%” set “CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar”
“%EXECUTABLE%” //IS//%SERVICE_NAME% ^
–Description “Apache Tomcat 8.0.29 Server - http://tomcat.apache.org/” ^
–DisplayName “%DISPLAYNAME%” ^
–Install “%EXECUTABLE%” ^
–LogPath “%CATALINA_BASE%\logs” ^
–StdError auto ^
–JvmOptions “-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed;-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties” ^
–Classpath “%CLASSPATH%” ^
–Jvm “%CATALINA_HOME%\bin\Java\jdk1.8.0_151\jre\bin\server\jvm.dll” ^
–StartMode jvm ^
–StopMode jvm ^
–StartPath “%CATALINA_HOME%” ^
–StopPath “%CATALINA_HOME%” ^
–StartClass org.apache.catalina.startup.Bootstrap ^
–StopClass org.apache.catalina.startup.Bootstrap ^
–StartParams start ^
–StopParams stop ^
–JvmMs 128 ^
–JvmMx 256
if not errorlevel 1 goto installed
echo Failed installing ‘%SERVICE_NAME%’ service
goto end
:installed
cd “%CURRENT_DIR%”
echo The service ‘%SERVICE_NAME%’ has been installed.
:end
service.bat end==
3.2 寫tomcat的批處理腳本,放在“D:\test\apache-tomcat-8.0.29\bin”下:
啟動服務.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==
jdk+tomcat+mysql+war打包整合成exe檔案,Windows下一鍵安裝 3.3 把打包好的war包 直接複制 放在“D:\test\apache-tomcat-8.0.29\webapps”下:
jdk+tomcat+mysql+war打包整合成exe檔案,Windows下一鍵安裝 好了,目前腳本什麼的都弄完了,就開始整合.exe檔案。
三、使用Inno Setup工具制作.exe檔案
1、在“D:\test”下建立一個.iss字尾的檔案,然後複制我下面給出的檔案内容,修改并執行它,工具就會在目前目錄建立一個名為“Output”檔案夾,裡面存有一個.exe的安裝包。
jdk+tomcat+mysql+war打包整合成exe檔案,Windows下一鍵安裝 [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:\test\apache-tomcat-8.0.29*”;DestDir:"{app}\apache-tomcat-8.0.29";Flags:igNoreversion recursesubdirs createallsubdirs
;拷貝mysql
Source:“D:\test\mysql-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-winx64\my.ini";Section:“mysqld”;Key:“basedir”; String:"{app}\mysql-5.5.40-winx64"
Filename:"{app}\mysql-5.5.40-winx64\my.ini";Section:“mysqld”;Key:“datadir”; String:"{app}\mysql-5.5.40-winx64\data"
Filename:"{app}\mysql-5.5.40-winx64\my.ini";Section:“mysqld”;Key:“port”; String:“3306”
Filename:"{app}\mysql-5.5.40-winx64\my.ini";Section:“client”;Key:“port”; String:“3306”
[Run]
Filename: “{app}\apache-tomcat-8.0.29\bin\Java\jdk1.8.0_151\bin\autoInstallJDK.bat”;
Filename: “{app}\mysql-5.5.40-winx64\bin\mysql_init.bat”;
Filename: “{app}\apache-tomcat-8.0.29\bin\啟動服務.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虛拟機和筆記本電腦都成功安裝了!這兩個都是全新的無配置環境的系統
jdk+tomcat+mysql+war打包整合成exe檔案,Windows下一鍵安裝 1 轉載 https://blog.csdn.net/qq_33240866/article/details/80066541