Created
April 23, 2012 02:06
-
-
Save djangofan/2468251 to your computer and use it in GitHub Desktop.
Customized SETENV.bat file for Yet Another Java Service Wrapper ( YAJSW )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO off | |
COLOR 4F | |
SET NAME=setenv.bat | |
TITLE Script %NAME% | |
ECHO %NAME% ... | |
::------------------------------------------------------------------- | |
:: Script configuration | |
::------------------------------------------------------------------- | |
::SETLOCAL ENABLEDELAYEDEXPANSION | |
SET "_JRE_DIR=Javasoft.1.6\jre" | |
::SET "_JRE_DIR=Program Files\Java\jre7" | |
::SET "_REQUIRED_JAR=appdir\lib\wrapper.jar" | |
SET "_REQUIRED_JAR=wrapper.jar" | |
SET /A CLOSE_DELAY=1 | |
::------------------------------------------------------------------- | |
:: Set window TITLE and also the 'RUN_DIR' and 'DIR_NAME' env variables | |
::------------------------------------------------------------------- | |
SET RUN_DIR=%~dp0 | |
SET RUN_DIR | |
FOR /F "delims=\" %%a IN ("%RUN_DIR%") DO SET "DIR_NAME=%%~nxa" | |
TITLE SETENV.bat running in folder %DIR_NAME% at directory %RUN_DIR% | |
::------------------------------------------------------------------- | |
:: Find and SET the variable _WRAPPER_HOME | |
::------------------------------------------------------------------- | |
SET "TMP_DIR=%~f0" | |
:LOOP | |
CALL :GET_DIR "%TMP_DIR%" | |
IF EXIST "%TMP_DIR%\%_REQUIRED_JAR%" ( | |
ECHO Found _WRAPPER_HOME at %TMP_DIR%\ | |
GOTO :HOMESET | |
) | |
IF "%TMP_DIR:~-1%" == ":" ( | |
ECHO Searched the parent folders of this directory up to the root directory and the | |
ECHO required object '%_REQUIRED_JAR%' was not successfully found. | |
) | |
GOTO :LOOP | |
:HOMESET | |
SET "_WRAPPER_HOME=%TMP_DIR%" | |
::------------------------------------------------------------------- | |
:: Remove trailing slash | |
::------------------------------------------------------------------- | |
IF %_WRAPPER_HOME:~-1%==\ SET "_WRAPPER_HOME=%_WRAPPER_HOME:~0,-1%" | |
::------------------------------------------------------------------- | |
:: Dynamically find and configure _JRE_HOME for wrapper | |
:: Ignores JAVA_HOME set by system environment | |
::------------------------------------------------------------------- | |
SET "_JREBINARY=%_JRE_DIR%\bin\java.exe" | |
IF EXIST "%RUN_DIR%\javahome.config" ( | |
ECHO. | |
ECHO Will read JRE home from javahome.config file | |
GOTO :READLOCKFILE | |
) | |
SET "TMP_DIR=%~f0" | |
:JRELOOP | |
CALL :GET_DIR "%TMP_DIR%" | |
IF EXIST "%_JREBINARY%" ( | |
ECHO Parent directory search found _JREBINARY within '%TMP_DIR%' | |
GOTO :JREFOUND | |
) | |
IF "%TMP_DIR:~-1%" == ":" ( | |
ECHO Parent directory search reached root and '%JREBINARY%' was not found. | |
GOTO :END | |
) | |
GOTO :JRELOOP | |
:JREFOUND | |
SET "_JRE_HOME=%TMP_DIR%\%_JRE_DIR%" | |
ECHO %_JRE_HOME%>javahome.config | |
ECHO Created file %RUN_DIR%javahome.config with value '%_JRE_HOME%' | |
GOTO :WRAPPERCONF | |
:READLOCKFILE | |
ECHO. | |
SET /P _JRE_HOME=<"%RUN_DIR%javahome.config" | |
ECHO The file %RUN_DIR%javahome.config shows _JRE_HOME to be '%_JRE_HOME%' | |
:WRAPPERCONF | |
::------------------------------------------------------------------- | |
:: Configure wrapper variables | |
::------------------------------------------------------------------- | |
:: Default java exe for running the wrapper | |
:: Note this is not the java exe for running the application. the exe for running the application is defined in the wrapper configuration file | |
SET "_JAVA_EXE=%_JRE_HOME%\bin\java.exe" | |
SET "_JAVAW_EXE=%_JRE_HOME%\bin\javaw.exe" | |
:: location of the wrapper jar file. necessary lib files will be loaded by this jar. | |
:: they must be at <_WRAPPER_HOME>\lib\... | |
SET "_WRAPPER_JAR=%_WRAPPER_HOME%\wrapper.jar" | |
SET "_WRAPPER_APP_JAR=%_WRAPPER_HOME%\wrapperApp.jar" | |
:: Default configuration used in genConfig | |
SET "_CONF_DEFAULT_FILE=%RUN_DIR%\wrapper.conf.default" | |
:: Setting java options for wrapper process. depending on the scripts used, the wrapper may require more memory. | |
SET RUN_DIR=%RUN_DIR:\=/% | |
SET JRECMD=%_JAVA_EXE% | |
SET JRECMD=%JRECMD:\=\\% | |
SET "_WRAPPER_JAVA_OPTIONS=-Xmx30m -Djna.tmpdir=%_WRAPPER_HOME%\tmp -Dwrapper_home=%RUN_DIR% -DMY_JRE=%JRECMD%" | |
:: The wrapper bat file for running the wrapper | |
SET "_WRAPPER_BAT=%_WRAPPER_HOME%\bat\wrapper.bat" | |
SET "_WRAPPERW_BAT=%_WRAPPER_HOME%\bat\wrapperW.bat" | |
:: Configuration file used by all bat files | |
SET "_CONF_FILE=%_WRAPPER_HOME%\conf\wrapper.conf" | |
GOTO :END | |
::------------------------------------------------------------------- | |
:: Functions | |
::------------------------------------------------------------------- | |
:GET_DIR | |
SET "TMP_DIR=%~dp1" | |
SET "TMP_DIR=%TMP_DIR:~0,-1%" | |
EXIT /B 0 | |
::------------------------------------------------------------------- | |
:: End script | |
::------------------------------------------------------------------- | |
:END | |
ECHO ------------------------------------ | |
SET _ | |
ECHO ------------------------------------ | |
ECHO.&ECHO. | |
FOR /l %%a IN (%CLOSE_DELAY%,-1,1) DO (TITLE SETENV_new.bat in %RUN_DIR% -- Closing in %%as&PING.exe -n 2 -w 1 127.0.0.1>nul) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment