TomCat的启动文件 start.bat 竟然有bug?!是我眼花吗?欢迎围观

偏执的执 2019-01-08 05:09:07
先说 bug:start.bat文件中永远也执行不到红色部分的代码,因为根据这个bat文件的逻辑

执行到 :okHome 时,文件 "%CATALINA_HOME%\bin\catalina.bat" 必然存在啊

这是 start.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     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem 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 and
rem limitations under the License.

if "%OS%" == "Windows_NT" setlocal
rem ---------------------------------------------------------------------------
rem Start script for the CATALINA Server
rem ---------------------------------------------------------------------------

rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%CURRENT_DIR%"
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end

:okHome

set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end

:okExec

rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

:end



各位大神,帮忙看看
...全文
71 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
偏执的执 2019-01-08
  • 打赏
  • 举报
回复
引用 2 楼 LCL_data 的回复:
他这里 应该双重校验把

上面if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome 校验一次
你说的这里在校验一次

第二次校验是在第一次校验成功的基础上,
你认为第二次校验会不成功吗?
十八道胡同 2019-01-08
  • 打赏
  • 举报
回复
他这里 应该双重校验把

上面if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome 校验一次
你说的这里在校验一次
偏执的执 2019-01-08
  • 打赏
  • 举报
回复
注意:当切换到父目录后,并且将 CATALINA_HOME 的值设为 父目录后,即执行完
cd ..
set "CATALINA_HOME=%cd%"
cd "%CURRENT_DIR%
这三行后,下面的 :gotHome,一样会执行

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧