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

这一生的挚爱 提交于 2020-01-24 23:47:32

问题


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 i.e 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

回答1:


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.




回答2:


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 .



回答3:


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.



来源:https://stackoverflow.com/questions/23154698/how-to-add-txt-file-to-the-war-archive-using-command-line-in-ms-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!