I have a batch script Change.bat as below which changes value of attribute httpPort
in server.xml file to a hardcoded value. But my script works only if the xml file is in the same folder where the batch script exists. BUT
The server.xml location is %~dp0\wlp\usr\servers\defa
and the batch script is in the same folder where 'wlp' folder resides. What changes do I need to do in the batch ?
<!-- Enable features -->
<!-- <feature>localConnector-1.0</feature> -->
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint host="*" httpPort="7680" httpsPort="9443" id="defaultHttpEndpoint"/>
<!-- Automatically expand WAR files and EAR files -->
setlocal EnableExtensions DisableDelayedExpansion
rem First check if the file to modify exists in directory of batch file.
if not exist "%XmlFile%" goto EndBatch
rem Define some environment variables which are needed later.
rem Search for the line containing attribute httpPort and get its
rem line number and the line itself loaded into environment variables.
for /F "tokens=1* delims=:" %%I in ('%SystemRoot%\System32\findstr.exe /L /N /C:httpPort= "%XmlFile%" 2^>nul') do (
rem If no line with attribute httpPort found, exit this batch file.
if not defined LineNumber goto EndBatch
rem Determine current number of attribute httpPort independent on where
rem this attribute is specified in the XML line and replace this number
rem in the line with the new port number as defined before.
rem It is required for this type of number replace that the other port
rem number for httpsPort is not the same number as current number for
rem httpPort as in this case both numbers would be replaced by the new
rem number. The attribute name and the equal sign cannot be included in
rem the string substitution as used here.
for /F %%I in ("!PortNumber:~1!") do set "PortNumber=%%~I"
endlocal & set "PortLine=%PortLine%"
rem Make sure the temporary file used next does not already exist.
del "%TmpFile%" 2>nul
rem Copy all lines from XML file to a temporary file including empty
rem lines with the exception of the line containing attribute httpPort
rem which is copied to temporary file with the modified port number.
for /F "tokens=1* delims=:" %%I in ('%SystemRoot%\System32\findstr.exe /R /N "^" "%XmlFile%" 2^>nul') do (
set /A LineCount+=1
if not !LineCount! == %LineNumber% (
) else (
rem Overwrite original file with temporary file automatically deleted on success.
move /Y "%TmpFile%" "%XmlFile%" >nul