want to alter xml

I  have a WAR  file   myapps.war   in  Ubuntu 10  box.

This  WAR file  has a   web.xml  file  at   myapps.war/WEB-INF/web.xml

I  want to  modify  this   xml  file.  In fact, I  want to change few  XML entries basically.

Whats the fastest  way I can do it ?  Please post  steps to check out.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can use sed with -i option.

You have to be more specific what you want to change.

First use sed and if the results are good use -i to commit changes to the file.
Please, elaborate on your sitauation
Do you mean to do it programmatically?

It is usually not something which people are doing every day - you'll want to eidt and modify it, the speed is normally not an issue, and and probably you'll sometimes need to restart your server.

If you create your web app with IDE - just recreate it, replace the WAR, and it will replace everything on the next starup - thta is probably the most natural way of doing it

Otheriwise that is normal XML file you'll probably use DOM to read and modify it, but I don't think peopel are usually doing it on web.xml
cofactorAuthor Commented:
Simply I  just  want to  change and save web.xml  in a  WAR  file  in Ubuntu 10 Server OS platform.  

whats the quickest solution ?

There is no programming involved here. Looking  for  some  Linux  commands  which could  solve  this problem easily.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

You don't need to change it in the .WAR file if you don't plane to deploy it more than in one place
Just start your server it will expmand .WAR and then change it in web.xml

Or rename your .WAR into. ZIP - use winzip - extract this web.xml and then zip it back and rename into .WAR agaian

Or do all in IDE, modify web.xml and  and then create new .WAR
cofactorAuthor Commented:
Had it been windows , I  would do the following ...

1. Open myapps.war  in  winzip
2.  Right click on web.xml  and open in Notepad
3.  Change web.xml  entries
4.  Save web.xml

Thats it.....very  easy . I  dont need to unzip  the entire war file.

But  this is in windows  .. I  want to do  the same staff  in Ubuntu ...so  my  question is How do I  do it in Ubuntu 10 server OS  platform ?
well, don't you have some place mapped to windows - I usually deal with Jars and wars this way - copy them to winodws compartible location and do everything form window
There is no doubt that there is unzip and zip progran on Ubuntu and I guess you can even rename it to .jar and then use jar form java tools, but simplest is to copy to windows
cofactorAuthor Commented:
>>>to .jar and then use jar form java tools, but simplest is to copy to windows
Negative.  I  do a FTP upload to  Ubuntu  from  windows.  Not  interested  to download back to windows for  this small  work.

I  wish to  do it  right  on the Ubuntu  platform.
This is the zip command, and I'm sure you can do it with that:

easier to unzip everything and zip it back
then to search for the option which will extract and replace one file

If you do it often with WAR and web.xml specifically - then it is not difficult to write such java program which will extract web.xml for you and another one which will repllace
There was a recent question on EE how to extract one specific file from .zip on Linux
Was it your question ?
Try XML Copy Editor
Here are interesting tools, links to alter xml

do FTP back and forth - it would be much faster than anything else
cofactorAuthor Commented:
>>>There was a recent question on EE how to extract one specific file from .zip on Linux
>>Was it your question.

Yes.  I use that when I  deploy  in exploded  format .  I can change file easily  using  that approach.  That works.

But now I have a .WAR  format  and so I'm in trouble.
>But now I have a .WAR  format  and so I'm in trouble.

But if you rename  or copy .WAR to .ZIP, it should work just as with zip
cofactorAuthor Commented:
>>>do FTP back and forth - it would be much faster than anything else

Negative.   because ..

I  do over SSH .  
size of  WAR  > 100 MB  .  
slow connection.
cofactorAuthor Commented:
>>>But if you rename  or copy .WAR to .ZIP, it should work just as with zip

Are you  trying to say

1.  rename .WAR to .ZIP
2.  extract only web.xml .  dont unzip  entire archive.
3. open vi  editor . change  xml entries.  save changes
4.  put it  back to  .zip  with  overwrite option
5. rename .ZIP  to .WAR

Is  it correct ?  IF so, I  dont know  the command for  step 4.
Yes, I was saying that.
I don't know the command for step 4 either, but I think I can find it among those zip options.
Let me see.
cofactorAuthor Commented:
>>>You can use sed with -i option.

Can you please  explain how  you  can use sed command to alter web.xml  inside .war  ?
this recommendation looks suprpaisinly simple:

zip -u stuff.jar file.txt

will update file.txt in stuff.zip . Note that for -u file.txt must already exist in the zip file, and will only be overwritten if it's newer than the one in the jar.
cofactorAuthor Commented:
>>>and  at this question about zip with GUI for Ubuntu:

Ubuntu 10 Server OS  does not have any GUI.  only  command line supported.
cofactorAuthor Commented:
>>>>zip -u stuff.jar file.txt

Don't  you need to  put the path of  the file here ?
Yes that's how i did it:
I put stuff.zip i  in a folder
then from that folder made directipry say WEB_INF
then placed in that folder modified web.xml
then wen back where i had staff.zip and WEB-INF

and said

zip -u stuff.zip WEB-INF/web.xml

and it upadted
I have not Ubuntu but CentOS but I think it should work on onther linux also
try on a small file first
so the path should aof course parallel the path within zip:
zip -u stuff.zip WEB-INF/web.xml
it even works not only with .zip but with .jar
Unfortunately, .war you still have to rename - it does not know this extension at least on my CENTOS
cofactorAuthor Commented:
>>>zip -u stuff.zip WEB-INF/web.xml

is there any interactive  option here ?  Does "i"  flag  work here. I  just want to  get an overwrite alert .  Yes / No  choice. ..is it possible ?

Also how do I remove a  file from zip ?  I  mistakenly added a file  in archive  in a wrong  path. So I  want to remove that  file also. what command to shoot here ?
zip -d stuff.zip WEB-INF/web.xml

will remove file

didn't see any interactive option

just type
it will print brief help
cofactorAuthor Commented:
zip -u stuff.zip WEB-INF/web.xml   is not  updating web.xml.

This command does not work.
I think web.xml in your folder needs to be newer than web.xml in the archive

It updated for me
Does it write

"updating ...
just tried one more time - everything works fine

but you need to have the ffile in parllaet folder, so that if
you are in some folder and archive ar.zip is in the same folder and in that archive you have
then you create folder
put file
abc into that folder - make sure that abc is modified later than the one in archibve
then go to your first folder

and do

zip -u ar.zip a_folder/abc

and it will write


and will updtae it
cofactorAuthor Commented:
>>>I think web.xml in your folder needs to be newer than web.xml in the archive

Its a newer file. I  have changed some entries.

I  have  new  web.xml  in deploy folder.
I  have stuff.zip  in deploy folder.

I do this ...

/default/deploy#   zip -u stuff.zip WEB-INF/web.xml

Then again I  do unzip to check  but I see its not updated.
>I  have  new  web.xml  in deploy folder.
no you need to have new web.xml in WEB-INF folder not in the same folder where you have zip but in parllel to how web.xml sits in the zip archove
And it should write "uodating..."
Once you see it writes updating then it will update
it cannot be that it wouold updte on centos but not on Ubuntu - I'm sure it is basically the same program
This is transcript of my test.
See, first time command
 zip -u forZipTest forZipTest/one/html
did nothing because file "html" in folder  forZipTest/one was of the same date as in archive
then I made  touch forZipTest/one/html to make a newer date
and next time it wrote "updating: forZipTest/one/html (deflated 44%)"
and it indeed updates - I tried with different content of the file also, not just touching

[comp test]$ ls
forZipTest  forZipTest.zip  html  one  ttt1.war  ttt.jar
[comp  test]$ zip -u forZipTest forZipTest/one/html
[comp  test]$ touch forZipTest/one/html
[comp  test]$ zip -u forZipTest forZipTest/one/html
updating: forZipTest/one/html (deflated 44%)
[comp  test]$ zip -Tv forZipTest
Archive:  forZipTest.zip
    testing: forZipTest/one/          OK
    testing: forZipTest/one/html      OK
    testing: forZipTest/one/sample/   OK
    testing: forZipTest/one/sample/one.xx.xml   OK
    testing: forZipTest/one.zip       OK
    testing: forZipTest/two/          OK
    testing: forZipTest/two/html      OK
    testing: forZipTest/two/sample/   OK
    testing: forZipTest/two/sample/two.xx.xml   OK
    testing: forZipTest/two.zip       OK
    testing: forZipTest/              OK
    testing: html                     OK
    testing: one/html                 OK
No errors detected in compressed data of forZipTest.zip.
test of forZipTest.zip OK
[comp  test]$ nedit log.txt

Open in new window

cofactorAuthor Commented:
>>>zip -u

I'm not clear about source and destination . I have stuff.zip  and  new  web.xml in the same folder.  ..so can I do this ?

zip -u   stuff.zip   web.xml   stuff.zip/WEB-INF/web.xml

>>>>And it should write "uodating..."

It does not .
No yoiu cannot. You need to create the path similar to the one inside your zip.
So if inside your stuff.zip you have web.xml within the folder WEB-INF, so you need to create the folder WEB-INF in your current directory and put yourneew variant of web.xml into that folder, then you go back to your prompt in current directory. Then from this prompt the real new version of filke will be accessible in the same path as it is sitting within the zip. And from this point you say
Zip -u stuff.zip WEB-INF/web.xml
Then it would write "updating..." And would update

I posted thge transcript of real example above - look at that and see how it works.
You cannot hjave it in the same folder as when youi specify the file oin the command itt should simultaneoiusly indicate the locatin of the file in zip and in the folder structure
You can alos think about it this way.

Suppose you had a .zip file in some folder.
Then you unzipped this zip file in this folder - so it creted for you the folder structure starting from this filder. Then someone , or you yourslef, modified one of the files within the folder structure where it was expanded. Then sitting in the same folder where you initially unzipped your zip file and still having your source zip file in that same folder, right here you are using zip -u command and you need to specify the path to that individual file which was modified on this command line. That path would be the same in your real unzipped directory structue and withinn the zip, so you specify this path as the second argument of your command (not counting -u which is not the argument but a switch).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.