简体   繁体   中英

How to add TXT file to the WAR archive using command-line in MS Windows

I have key.txt file in E:/ drive and app.war file in C:/ drive. How to copy key.txt to the subfolder of the app.war file ie WebContent/WEB-INF. Key should copy to the WEB-INF folder. I want result like(after unzipping war file)

WebContent
|
|->META-INF
|->WEB-INF
        |
        |->key.txt

Finally i got answer, for this i used.

mkdir c:/WEB-INF
cd WEB-INF
xcopy D:/key.txt C:/WEB-INF
jar uvf app.war /WEB-INF/key.txt

No need of unzipping and again zipping.

You can use the jar command to extract and re-create your WAR file:

mkdir mywar
cd mywar
jar -xf c:\path\to\mywar.war
copy c:\path\to\key.txt WEB-INF\
jar -cf c:\path\to\mynewwar.war .

If you are building the war file in the first place, presumably with a build tool such as Ant, Maven, or Gradle, then you should bundle it in at build time using that tool.

If you really have to add the file after the fact, then you can take advantage of the fact that a .war file is really just a .zip file. Unzip it, add key.txt in the desired location, and then zip it back up.

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