setclasspath.bat(2)
一、阅读说明
1 术语说明
1.1 下述内容使用“服务器”均代表Tomcat 7.0.75Web服务器
1.2 下述内容使用%SERVER_PATH%表示服务器根目录
二、setclasspath.bat文件源码
1 setclasspath.bat文件位置
setclasspath.bat文件位置:%SERVER_PATH%\bin\setclasspath.bat
2 源码内容
(以下内容经处理,去除不必要的信息)
1 @echo off 2 3 rem Make sure prerequisite environment variables are set 4 5 rem In debug mode we need a real JDK (JAVA_HOME) 6 if ""%1"" == ""debug"" goto needJavaHome 7 8 rem Otherwise either JRE or JDK are fine 9 if not "%JRE_HOME%" == "" goto gotJreHome 10 if not "%JAVA_HOME%" == "" goto gotJavaHome 11 echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined 12 echo At least one of these environment variable is needed to run this program 13 goto exit 14 15 :needJavaHome 16 rem Check if we have a usable JDK 17 if "%JAVA_HOME%" == "" goto noJavaHome 18 if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome 19 if not exist "%JAVA_HOME%\bin\javaw.exe" goto noJavaHome 20 if not exist "%JAVA_HOME%\bin\jdb.exe" goto noJavaHome 21 if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome 22 set "JRE_HOME=%JAVA_HOME%" 23 goto okJava 24 25 :noJavaHome 26 echo The JAVA_HOME environment variable is not defined correctly. 27 echo It is needed to run this program in debug mode. 28 echo NB: JAVA_HOME should point to a JDK not a JRE. 29 goto exit 30 31 :gotJavaHome 32 rem No JRE given, use JAVA_HOME as JRE_HOME 33 set "JRE_HOME=%JAVA_HOME%" 34 35 :gotJreHome 36 rem Check if we have a usable JRE 37 if not exist "%JRE_HOME%\bin\java.exe" goto noJreHome 38 if not exist "%JRE_HOME%\bin\javaw.exe" goto noJreHome 39 goto okJava 40 41 :noJreHome 42 rem Needed at least a JRE 43 echo The JRE_HOME environment variable is not defined correctly 44 echo This environment variable is needed to run this program 45 goto exit 46 47 :okJava 48 rem Don't override the endorsed dir if the user has set it previously 49 if not "%JAVA_ENDORSED_DIRS%" == "" goto gotEndorseddir 50 rem Set the default -Djava.endorsed.dirs argument 51 set "JAVA_ENDORSED_DIRS=%CATALINA_HOME%\endorsed" 52 :gotEndorseddir 53 54 rem Don't override _RUNJAVA if the user has set it previously 55 if not "%_RUNJAVA%" == "" goto gotRunJava 56 rem Set standard command for invoking Java. 57 rem Also note the quoting as JRE_HOME may contain spaces. 58 set _RUNJAVA="%JRE_HOME%\bin\java.exe" 59 :gotRunJava 60 61 rem Don't override _RUNJDB if the user has set it previously 62 rem Also note the quoting as JAVA_HOME may contain spaces. 63 if not "%_RUNJDB%" == "" goto gotRunJdb 64 set _RUNJDB="%JAVA_HOME%\bin\jdb.exe" 65 :gotRunJdb 66 67 goto end 68 69 :exit 70 exit /b 1 71 72 :end 73 exit /b 0
三、源码分析
1 @echo off 2 3 rem In debug mode we need a real JDK (JAVA_HOME) 4 if ""%1"" == ""debug"" goto needJavaHome 5 rem 若第一个参数为debug,则跳转至needJavaHome 6 7 rem Otherwise either JRE or JDK are fine 8 if not "%JRE_HOME%" == "" goto gotJreHome 9 rem 若存在变量JRE_HOME,则跳转至gotJreHome 10 if not "%JAVA_HOME%" == "" goto gotJavaHome 11 rem 若存在变量JAVA_HOME,则跳转至gotJavaHome 12 echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined 13 echo At least one of these environment variable is needed to run this program 14 goto exit 15 16 :needJavaHome 17 rem Check if we have a usable JDK 18 if "%JAVA_HOME%" == "" goto noJavaHome 19 rem 若变量JAVA_HOME为空,则跳转至noJavaHome 20 if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome 21 rem 若不存在%JAVA_HOME%\bin\java.exe文件,则跳转至noJavaHome 22 if not exist "%JAVA_HOME%\bin\javaw.exe" goto noJavaHome 23 rem 若不存在%JAVA_HOME%\bin\javaw.exe文件,则跳转至noJavaHome 24 if not exist "%JAVA_HOME%\bin\jdb.exe" goto noJavaHome 25 rem 若不存在%JAVA_HOME%\bin\jdb.exe,则跳转至noJavaHome 26 if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome 27 rem 若不存在%JAVA_HOME%\bin\javac.exe,则跳转至noJavaHome 28 set "JRE_HOME=%JAVA_HOME%" 29 rem 设变量JRE_HOME为%JAVA_HOME% 30 goto okJava 31 32 :noJavaHome 33 echo The JAVA_HOME environment variable is not defined correctly. 34 echo It is needed to run this program in debug mode. 35 echo NB: JAVA_HOME should point to a JDK not a JRE. 36 goto exit 37 38 :gotJavaHome 39 rem No JRE given, use JAVA_HOME as JRE_HOME 40 set "JRE_HOME=%JAVA_HOME%" 41 rem 设变量JRE_HOME=%JAVA_HOME% 42 43 :gotJreHome 44 rem Check if we have a usable JRE 45 if not exist "%JRE_HOME%\bin\java.exe" goto noJreHome 46 rem 若不存在%JRE_HOME%\bin\java.exe文件,则跳转至noJreHome 47 if not exist "%JRE_HOME%\bin\javaw.exe" goto noJreHome 48 rem 若不存在%JRE_HOME%\bin\javaw.exe文件,则跳转至noJreHome 49 goto okJava 50 51 :noJreHome 52 rem Needed at least a JRE 53 echo The JRE_HOME environment variable is not defined correctly 54 echo This environment variable is needed to run this program 55 goto exit 56 57 :okJava 58 rem Don't override the endorsed dir if the user has set it previously 59 if not "%JAVA_ENDORSED_DIRS%" == "" goto gotEndorseddir 60 rem 若存在变量JAVA_ENDORSED_DIRS不为空,则跳转至gotEndorseddir 61 rem Set the default -Djava.endorsed.dirs argument 62 set "JAVA_ENDORSED_DIRS=%CATALINA_HOME%\endorsed" 63 rem 若存在变量JAVA_ENDORSED_DIRS为空,则设其值为%CATALINA_HOME%\endorsed 64 :gotEndorseddir 65 66 rem Don't override _RUNJAVA if the user has set it previously 67 if not "%_RUNJAVA%" == "" goto gotRunJava 68 rem 若变量_RUNJAVA不为空,则跳转至gotRunJava 69 rem Set standard command for invoking Java. 70 rem Also note the quoting as JRE_HOME may contain spaces. 71 set _RUNJAVA="%JRE_HOME%\bin\java.exe" 72 rem 若变量_RUNJAVA为空,则设其值为%JRE_HOME%\bin\java.exe 73 :gotRunJava 74 75 rem Don't override _RUNJDB if the user has set it previously 76 rem Also note the quoting as JAVA_HOME may contain spaces. 77 if not "%_RUNJDB%" == "" goto gotRunJdb 78 rem 若变量_RUNJDB不为空,则跳转至gotRunJdb 79 set _RUNJDB="%JAVA_HOME%\bin\jdb.exe" 80 rem 若变量_RUNJDB为空,则设其值为%JAVA_HOME%\bin\jdb.exe 81 :gotRunJdb 82 83 goto end 84 85 :exit 86 exit /b 1 87 rem 退出并返回1 88 89 :end 90 exit /b 0 91 rem 退出并返回0
四、结论
setclasspath.bat主要做了检查Java环境变量并设置新的变量
版权声明:本文原创发表于 博客园,作者为 微小处存bug 本文欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则视为侵权。
感谢您的阅读,若您觉得本文对您有所帮助,请点击右下角的推荐按钮。