参考:重点参考的文章:/qq_33240866/article/details/80066541(下面用文章一表示)
辅助的文章:/liuhaomatou/article/details/52576162
ps:在看文章的时候还是要仔细阅读,别马虎。特别时英文部分,自己还是要去看看是什么意思,别只复制粘贴。
/qq_38686305/article/details/84392942
经历了:安装虚拟机(用于测试能不能安装成功exe文件《1,在虚拟机中测试MySQL能不能用脚本文件安装使用-----》2.测试tomcat通过脚本文件是否安装成功》1.2步都能再虚拟机中安装成功说明MySQL和tomcat的文件都没有错,就可以打包成exe文件,再到虚拟机中测试安装。分步测试的好处:1,2步有问题针对性的解决,不需要重复打包成exe测试)
步骤:
一,安装虚拟机;
/jongsuk_sun/article/details/100772708
准备:(ps:需要注意的是项目使用的连接数据库的驱动和mysql软件版本的对应关系,否则连接数据库会报错)
参考文章一:中的步骤一准备
下载mysql:/downloads/mysql/
下载步骤:/jongsuk_sun/article/details/101218227
ps:
二,写mysql中的脚本:
1.1 my.ini (ps:注意与参考文件不同的地方)
主要是脚本文件的内容:
下面是自己修改后的脚本文件,与文章一有不同的地方在下面有标注。
# MySQL Server Instance Configuration File# ----------------------------------------------------------------------# Generated by the MySQL Server Instance Configuration Wizard### Installation Instructions# ----------------------------------------------------------------------## On Linux you can copy this file to /etc/f to set global options,# mysql-data-dir/f to set server-specific options# (@localstatedir@ for this installation) or to# ~/.f 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="C:\Program Files\MySQL\MySQL Server X.Y\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="C:\Program Files\MySQL\MySQL Server X.Y\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 onport=3306#Path to installation directory. All paths are usually resolved relative to this.basedir="E:\test\mysql-8.0.17-winx64"#Path to the database rootdatadir="E:\test\mysql-8.0.17-winx64\data\"# The default character set that will be used when a new schema or table is# created and no character set is definedcharacter-set-server=utf8# The default storage engine that will be used when create new tables whendefault-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=64Kread_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
注意的地方:
一定,一定,一定 不要在安装目录下创建data文件夹,(自己去创建会报错!!!,后面通过脚本文件初始化时系统会自动创建的!!!)
1.2 ps:这部分与文章一有不同:数据库的sql文件是存放在:
ps:sql文件要添加创建库,使用库的语句:
1.3 MySQL的批处理脚本文件;
cd /d %~dp0 "%cd%\mysqld.exe" --initialize-insecure --user=mysql --consoleecho -----mysql init succee-----pause;mysqld install mysql --defaults-file="E:\test\mysql-8.0.17-winx64\my.ini"echo -----mysql service install succee-----pause;net start mysqlsc config mysql start=auto net stop mysqlnet start mysqlecho 安装完毕 pause;"%cd%\mysqladmin" -u root password rootecho 修改密码完毕 pause;cd .. "%cd%\bin\mysql.exe" -uroot -proot < "%cd%\sql\aviation.sql" echo 建表完毕 pause;echo 建立新用户完毕
ps:mysql的批处理文件中不要指定my.ini文件位置。指定了位置,mysql就必须安装在这个路径下面,要不就要报错。
ps:对mysql批处理文件内容的意思的了解:
/jongsuk_sun/article/details/101022644
或者对照参考二的文章。
对mysql文件的就组装完毕了,这时候可以将文件放在虚拟机中,执行批处理文件mysql_init.bat 测试是否能安装成功!,如果不能,就看cmd中打印出来的错误提示,
二,对照文章一,中对 jdk,tomcat的操作:
autoInstallJDK.bat文件内容:
@echo off echocd ..echo "%~dp0"echo "%cd%"set jdkpath=%cd%\apache-tomcat-8.0.29\bin\Java\jdk1.8.0_151echo %jdkpath%setx JAVA_HOME "%jdkpath%" -msetx CLASSPATH ".;%%JAVA_HOME%%\lib\tools.jar;%%JAVA_HOME%%\lib\dt.jar" -mecho %Path%echo %Path%|find /i "%java_home%" && set IsNull=true || set IsNull=falseecho %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" /fsetx Path "%%JAVA_HOME%%\bin;%Path%")exit
修改service.bat文件;
@echo offrem Licensed to the Apache Software Foundation (ASF) under one or morerem contributor license agreements. See the NOTICE file distributed withrem this work for additional information regarding copyright ownership.rem The ASF licenses this file to You under the Apache License, Version 2.0rem (the "License"); you may not use this file except in compliance withrem the License. You may obtain a copy of the License atremrem/licenses/LICENSE-2.0remrem Unless required by applicable law or agreed to in writing, softwarerem distributed under the License is distributed on an "AS IS" BASIS,rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.rem See the License for the specific language governing permissions andrem limitations under the License.rem ---------------------------------------------------------------------------rem NT Service Install/Uninstall scriptremrem Optionsrem installInstall the service using Tomcat8 as service name.rem Service is installed using default settings.rem remove Remove the service from the System.remrem name (optional) If the second argument is present it is consideredrem to be new service namerem ---------------------------------------------------------------------------setlocalrem Guess CATALINA_HOME if not definedset "CURRENT_DIR=%cd%"rem if not "%CATALINA_HOME%" == "" goto gotHomeset "CATALINA_HOME=%cd%"if exist "%CATALINA_HOME%\bin\tomcat8.exe" goto okHomerem CD to the upper dircd ..set "CATALINA_HOME=%cd%":gotHomeif exist "%CATALINA_HOME%\bin\tomcat8.exe" goto okHomeecho The tomcat8.exe was not found...echo The CATALINA_HOME environment variable is not defined correctly.echo This environment variable is needed to run this programgoto end:okHomerem Make sure prerequisite environment variables are setif not "%JAVA_HOME%" == "" goto gotJdkHomeif not "%JRE_HOME%" == "" goto gotJreHomeecho Neither the JAVA_HOME nor the JRE_HOME environment variable is definedecho Service will try to guess them from the registry.goto okJavaHome:gotJreHomeif not exist "%JRE_HOME%\bin\java.exe" goto noJavaHomeif not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHomegoto okJavaHome:gotJdkHomeset "JRE_HOME=%JAVA_HOME%\jre"if not exist "%JAVA_HOME%\jre\bin\java.exe" goto okJavaHomeif not exist "%JAVA_HOME%\jre\bin\javaw.exe" goto noJavaHomeif not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHomeif not "%JRE_HOME%" == "" goto okJavaHomeset "JRE_HOME=%JAVA_HOME%\jre"goto okJavaHome:noJavaHomeecho The JAVA_HOME environment variable is not defined correctlyecho This environment variable is needed to run this programecho NB: JAVA_HOME should point to a JDK not a JREgoto end:okJavaHomeif not "%CATALINA_BASE%" == "" goto gotBaseset "CATALINA_BASE=%CATALINA_HOME%":gotBaseset "EXECUTABLE=%CATALINA_HOME%\bin\tomcat8.exe"rem Set default Service nameset SERVICE_NAME=Tomcat8set DISPLAYNAME=Apache Tomcat 8.0if "x%1x" == "xx" goto doInstallset SERVICE_CMD=%1shiftif "x%1x" == "xx" goto checkServiceCmdset SERVICE_NAME=%1set DISPLAYNAME=Apache Tomcat 8.0 %1shiftif "x%1x" == "xx" goto checkServiceCmdecho Unknown parameter "%1"goto displayUsage:checkServiceCmdif /i %SERVICE_CMD% == install goto doInstallif /i %SERVICE_CMD% == remove goto doRemoveif /i %SERVICE_CMD% == uninstall goto doRemoveecho Unknown parameter "%SERVICE_CMD%":displayUsageecho.echo Usage: service.bat install/remove [service_name]goto end:doRemoverem Remove the serviceecho Removing the service '%SERVICE_NAME%' ...echo Using CATALINA_BASE: "%CATALINA_BASE%""%EXECUTABLE%" //DS//%SERVICE_NAME% ^--LogPath "%CATALINA_BASE%\logs"if not errorlevel 1 goto removedecho Failed removing '%SERVICE_NAME%' servicegoto end:removedecho The service '%SERVICE_NAME%' has been removedgoto end:doInstallset "JRE_HOME=%JAVA_HOME%\jre"rem Install the serviceecho 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 jvmrem set "JVM=%JRE_HOME%\bin\server\jvm.dll"rem if exist "%JVM%" goto foundJvmrem Try to use the client jvmset "JVM=%JRE_HOME%\bin\client\jvm.dll"if exist "%JVM%" goto foundJvmecho Warning: Neither 'server' nor 'client' jvm.dll was found at JRE_HOME.set JVM="%JAVA_HOME%\jre\bin\client\jvm.dll":foundJvmecho 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 - /" ^--DisplayName "%DISPLAYNAME%" ^--Install "%EXECUTABLE%" ^--LogPath "%CATALINA_BASE%\logs" ^--StdOutput auto ^--StdError auto ^--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 ^--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" ^--JvmMs 128 ^--JvmMx 256if not errorlevel 1 goto installedecho Failed installing '%SERVICE_NAME%' servicegoto end:installedecho The service '%SERVICE_NAME%' has been installed.:endcd "%CURRENT_DIR%"
创建tomcat的启动文件;
echocall "%~dp0%service.bat" install tomcat8echosc config tomcat8 start= auto sc start tomcat8rem 下面两句是设置到服务里自动启动的wmic service where name="tomcat8" changestartmode "automatic"wmic service where name="tomcat8" startserviceexit
将javaweb项目打包成war包放到webapps下。
安装Inno Setup ,创建now.iss文件:
ps:如果最开始是txt文件就将脚本复制粘贴进去,之后修改成iss文件,打开会存在中文乱码的问题,还是iss文件的时候复制粘贴脚本语句吧。
这样就成功啦。赶紧在虚拟机上测试,测试
tomcat中的日志信息:
/qlqwjy/p/8036091.html
在虚拟机上执行exe文件,环境都配置成功。可以访问到界面了,但是项目无法连接到数据库:
1,考虑mysql服务是否启动,MySQL服务端口是否可以正常访问。
通过在虚拟机中安装navicat图形软件去测试。遇见的问题,解决如下:
navicat 连接 mysql 报错:client does not support authentication protocal requested by server
/zichuan/p/9203129.html
解决Mysql数据库访问出现“Too many connections”问题;
方式一:/u012898245/article/details/79356907这样设置重启之后会复原。
方式二:直接在配置文件中修改(ps;百度好多都是.cnf文件中修改,但是我的mysql中没有那个文件,只有my.ini。反正就是在有配置max_connections的文件中修改)
修改完毕,重启mysql服务,如果重启服务有问题,就删除MySQL服务,删除MySQL文件夹中的data文件夹,重新初始化mysql,重新生成MySQL服务,,,,,,
2,打包成exe之后:MySQL安装成功,navicat也能访问到MySQL服务,tomcat安装成功,能访问到首页信息以及能处理不需要去访问数据库的请求。但需要访问数据库的请求就一直都在连接,没有返回值;如下图。
-------》情况分析:一定是与数据库连接有问题导致的。
最终原因:
mysql用的是mysql-8.0.17-winx64,但是javaweb中连接mysql的驱动却是mysql-connector-java-5.1.31-bin.jar。驱动版本太低导致无法访问到mysql数据库!!!(ps:自己在做项目的时候数据库用的版本是mysql-5.5.27-winx64,在项目中用5.1.31的驱动是没有问题的。但是下的免安装的mysql是mysql-8.0.17-winx64《至于为什么下载这个版本是因为进入MySQL,看到的这个版本,主要是上面一系列对mysql的操作能成功安装mysql服务》)
解决:重新下载mysql,下载的mysql-5.7.15-winx64,按照前面对mysql的操作去做,
问题终于解决啦~~~~~~~~~~~~,在虚拟机上运行exe文件,成功访问到网页,通畅的浏览啦!!!!
ps:打包成功的exe文件运行,选择安装目录的时候,我这个应该是:E盘下。否则,安装mysql的时候服务安装不上ERROR (HY000): Can't connect to MySQL server on 'localhost' (10061),导致无法访问到数据库。
至于原因:我猜测是因为mysql中的my.ini文件中的
basedir="E:\test\mysql-8.0.17-winx64"
datadir="E:\test\mysql-8.0.17-winx64\data\"这两个地址是在E盘下面。如果将项目安装到其他盘,就访问那两个地址就是有误的。
然而事实并原因不是这样的,在安装MySQL之后my.ini文件下,那两个路径也改变了:
那到底是为什么呢?(查看启动的脚本,发现下面的地址没有改变,所以问题实在这吗?)
其他思考方面还是挺多的:
1,查看tomcat中记录错误信息的日志,有没有报错信息
tomcat日志文件内容:/jongsuk_sun/article/details/103165175
2.查看mysql用户权限。是不是因为登陆数据库的用户权限不够?
3,以及连接数据库的配置文件有没有错
4.思考方向还有很多吧。。。
哈哈哈哈哈哈,终于知道是为什么,自己打包的exe项目必须在E盘下安装了!!!
修改mysql_init.bat文件后,重新运行now.iss文件生成exe文件。这下在安装的时候用户自定义安装路径也没有问题了!!!
ps:now.iss文件中是inno setup脚本语句,脚本语句的解释,参考:
/jongsuk_sun/article/details/103147596
如果觉得《jdk+tomcat+mysql+项目打包成exe文件安装》对你有帮助,请点赞、收藏,并留下你的观点哦!