/maven/bin/mvn.bat

https://github.com/ajakubo1/opennms · Batch · 196 lines · 156 code · 40 blank · 0 comment · 38 complexity · 055429c9bd34a755a729e9e2e43fdada MD5 · raw file

  1. @REM ----------------------------------------------------------------------------
  2. @REM Licensed to the Apache Software Foundation (ASF) under one
  3. @REM or more contributor license agreements. See the NOTICE file
  4. @REM distributed with this work for additional information
  5. @REM regarding copyright ownership. The ASF licenses this file
  6. @REM to you under the Apache License, Version 2.0 (the
  7. @REM "License"); you may not use this file except in compliance
  8. @REM with the License. You may obtain a copy of the License at
  9. @REM
  10. @REM http://www.apache.org/licenses/LICENSE-2.0
  11. @REM
  12. @REM Unless required by applicable law or agreed to in writing,
  13. @REM software distributed under the License is distributed on an
  14. @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. @REM KIND, either express or implied. See the License for the
  16. @REM specific language governing permissions and limitations
  17. @REM under the License.
  18. @REM ----------------------------------------------------------------------------
  19. @REM ----------------------------------------------------------------------------
  20. @REM Maven2 Start Up Batch script
  21. @REM
  22. @REM Required ENV vars:
  23. @REM JAVA_HOME - location of a JDK home dir
  24. @REM
  25. @REM Optional ENV vars
  26. @REM M2_HOME - location of maven2's installed home dir
  27. @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
  28. @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
  29. @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
  30. @REM e.g. to debug Maven itself, use
  31. @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
  32. @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
  33. @REM ----------------------------------------------------------------------------
  34. @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
  35. @echo off
  36. @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
  37. @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
  38. @REM set %HOME% to equivalent of $HOME
  39. if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
  40. @REM Execute a user defined script before this one
  41. if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
  42. if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
  43. :skipRcPre
  44. set ERROR_CODE=0
  45. @REM set local scope for the variables with windows NT shell
  46. if "%OS%"=="Windows_NT" @setlocal
  47. if "%OS%"=="WINNT" @setlocal
  48. @REM ==== START VALIDATION ====
  49. if not "%JAVA_HOME%" == "" goto OkJHome
  50. echo.
  51. echo Error: JAVA_HOME not found in your environment. >&2
  52. echo Please set the JAVA_HOME variable in your environment to match the >&2
  53. echo location of your Java installation. >&2
  54. echo.
  55. goto error
  56. :OkJHome
  57. if exist "%JAVA_HOME%\bin\java.exe" goto chkMHome
  58. echo.
  59. echo Error: JAVA_HOME is set to an invalid directory. >&2
  60. echo JAVA_HOME = "%JAVA_HOME%" >&2
  61. echo Please set the JAVA_HOME variable in your environment to match the >&2
  62. echo location of your Java installation. >&2
  63. echo.
  64. goto error
  65. :chkMHome
  66. if not "%M2_HOME%"=="" goto valMHome
  67. if "%OS%"=="Windows_NT" SET "M2_HOME=%~dp0.."
  68. if "%OS%"=="WINNT" SET "M2_HOME=%~dp0.."
  69. if not "%M2_HOME%"=="" goto valMHome
  70. echo.
  71. echo Error: M2_HOME not found in your environment. >&2
  72. echo Please set the M2_HOME variable in your environment to match the >&2
  73. echo location of the Maven installation. >&2
  74. echo.
  75. goto error
  76. :valMHome
  77. :stripMHome
  78. if not "_%M2_HOME:~-1%"=="_\" goto checkMBat
  79. set "M2_HOME=%M2_HOME:~0,-1%"
  80. goto stripMHome
  81. :checkMBat
  82. if exist "%M2_HOME%\bin\mvn.bat" goto init
  83. echo.
  84. echo Error: M2_HOME is set to an invalid directory. >&2
  85. echo M2_HOME = "%M2_HOME%" >&2
  86. echo Please set the M2_HOME variable in your environment to match the >&2
  87. echo location of the Maven installation >&2
  88. echo.
  89. goto error
  90. @REM ==== END VALIDATION ====
  91. :init
  92. @REM Decide how to startup depending on the version of windows
  93. @REM -- Windows NT with Novell Login
  94. if "%OS%"=="WINNT" goto WinNTNovell
  95. @REM -- Win98ME
  96. if NOT "%OS%"=="Windows_NT" goto Win9xArg
  97. :WinNTNovell
  98. @REM -- 4NT shell
  99. if "%@eval[2+2]" == "4" goto 4NTArgs
  100. @REM -- Regular WinNT shell
  101. set MAVEN_CMD_LINE_ARGS=%*
  102. goto endInit
  103. @REM The 4NT Shell from jp software
  104. :4NTArgs
  105. set MAVEN_CMD_LINE_ARGS=%$
  106. goto endInit
  107. :Win9xArg
  108. @REM Slurp the command line arguments. This loop allows for an unlimited number
  109. @REM of agruments (up to the command line limit, anyway).
  110. set MAVEN_CMD_LINE_ARGS=
  111. :Win9xApp
  112. if %1a==a goto endInit
  113. set MAVEN_CMD_LINE_ARGS=%MAVEN_CMD_LINE_ARGS% %1
  114. shift
  115. goto Win9xApp
  116. @REM Reaching here means variables are defined and arguments have been captured
  117. :endInit
  118. SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
  119. @REM -- 4NT shell
  120. if "%@eval[2+2]" == "4" goto 4NTCWJars
  121. @REM -- Regular WinNT shell
  122. for %%i in ("%M2_HOME%"\boot\plexus-classworlds-*) do set CLASSWORLDS_JAR="%%i"
  123. goto runm2
  124. @REM The 4NT Shell from jp software
  125. :4NTCWJars
  126. for %%i in ("%M2_HOME%\boot\plexus-classworlds-*") do set CLASSWORLDS_JAR="%%i"
  127. goto runm2
  128. @REM Start MAVEN2
  129. :runm2
  130. set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
  131. %MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %CLASSWORLDS_JAR% "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
  132. if ERRORLEVEL 1 goto error
  133. goto end
  134. :error
  135. if "%OS%"=="Windows_NT" @endlocal
  136. if "%OS%"=="WINNT" @endlocal
  137. set ERROR_CODE=1
  138. :end
  139. @REM set local scope for the variables with windows NT shell
  140. if "%OS%"=="Windows_NT" goto endNT
  141. if "%OS%"=="WINNT" goto endNT
  142. @REM For old DOS remove the set variables from ENV - we assume they were not set
  143. @REM before we started - at least we don't leave any baggage around
  144. set MAVEN_JAVA_EXE=
  145. set MAVEN_CMD_LINE_ARGS=
  146. goto postExec
  147. :endNT
  148. @endlocal & set ERROR_CODE=%ERROR_CODE%
  149. :postExec
  150. if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
  151. if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
  152. :skipRcPost
  153. @REM pause the batch file if MAVEN_BATCH_PAUSE is set to 'on'
  154. if "%MAVEN_BATCH_PAUSE%" == "on" pause
  155. if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
  156. cmd /C exit /B %ERROR_CODE%