简体   繁体   中英

batch file to edit a text file

I need this to deploy a web application using a war file.

I have worked out how to create a war file using jar command. But when a user deploys the web application a certain string in the web.xml file must be updated to reflect the users environment.

Eg in web.xml file I have entry (example):

<init-param>
 <param-name>colour</param-name>
 <param-value>red</param-value>
</init-param>

I want to ask user for colour and then update war file. Obviously so user deploys the correct thing. I can update the file using jar uf - no problem there. Eg the text above would be inserted in a set location in the text file. Being specific, would be after the text .

I am happy to do this on command line. Eg something like this:

  1. Prompt user for string.
  2. update string in web.xml
  3. update web.xml file in war deployment file.
  4. Then happy for user to manually copy war file to correct location.

How would I program this? For now, Windows only (but will want linux support shortly). A batch file? Any suggestions for how to approach?

按照本示例中的说明使用Maven资源过滤: http : //maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

search and replace with GNU sed :

(for your Q1 & Q2)

@echo off&setlocal
REM set the old color in a variable
set "oldstring=red"
REM prompt the user for a string
set/p "string=enter string: "
REM update string in web.xml
sed -i "s/%oldstring%/%string%/i" web.xml
type web.xml

.. output is:

enter string: green
<init-param>
 <param-name>colour</param-name>
 <param-value>green</param-value>
</init-param>

I have no clue of war files . Please explain, then I will improve my code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM