tomcat jdk一键打包安装

说明:有很多没接触过的tomcat的用户不会配置JDK环境,所以老板要求实现傻瓜式安装

用到的软件:1.tomcat8     2.jdk    3.  inno setup编辑器

步骤一:首先新建一个文件夹里面放需要打包的文件

将jdk放入tomcat的bin目录下

步骤二:修改文件

首先是autoInstallJDK.bat,这是jdk环境自动配置放在jdk的bin目录下

扫描二维码关注公众号,回复: 2883690 查看本文章

autoInstallJDK.bat内容

@echo off
echo ------begin----
:: 退到上级目录
cd ..


:: 获取jdk 的全路径,全路径=当前路径+jdk路径
:: "%~dp0" 这个是最起始的条用bat的cmd 的路径 所以我们要使用cd ..后退一个目录后用"%cd%" 来获取当前目录


echo "%~dp0"


echo "%cd%"


::设置jdkpath变量
set jdkpath=%cd%


echo %jdkpath%


::setx variable value -m
:: setx 这个是用来设置环境变量的,并且会写入注册表. variable,会被覆盖,此操作不可逆的
:: variable 代表键 value代表值 -m代表写入系统环境变量,如果没有该参数会写入当前用户环境变量.


setx JAVA_HOME "%jdkpath%"
echo JAVA_HOME

setx CLASSPATH ".;%%JAVA_HOME%%\lib\tools.jar;%%JAVA_HOME%%\lib\dt.jar"


echo %Path%


::追加path环境变量 find 后面/i代表忽略大小写 &&执行成功执行的命令 ||执行失败执行的命令
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

Tomcat启动服务,放在tomcat的bin下面

 启动服务.bat

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

最后是tomcat的bin下面的service.bat文件

@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.5

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.5 %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.5.32 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\jdk_package\jdk\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

配置结束开始打包

1.启动inno setup

新建一个文件把下面代码复制过去

; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!

#define MyAppName "我的程序"
#define MyAppVersion "1.5"
#define MyAppPublisher "我的公司"
#define MyAppURL "http://www.example.com/"

[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{BE00C334-6BEA-4350-953D-04BF90EA290F}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName=remoteplayer
OutputBaseFilename=setup11
SetupIconFile=E:\test1\logo.ico
Compression=lzma
SolidCompression=yes

[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "E:\test1\apache-tomcat-8.5.32\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

[Run]
Filename: "{app}\bin\jdk_package\jdk\bin\autoInstallJDK.bat";
Filename: "{app}\bin\启动服务.bat";

注意这个位置,没有主执行文件,然后添加文件夹,然后打包就可以了

生成的exe就在output里面

右键以管理员身份运行进行安装

猜你喜欢

转载自www.cnblogs.com/D-MEIYI/p/9508665.html
今日推荐