File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Modification of JSP file using ANT

 
Milton Quranda
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I wanted to know how i can modify a line in an existing jsp page and put it in a war file.

For e.g. i have a war file called peace.war. There are few jsp pages in it and some xml documents.

Now before deploying the war in a web server i need to add another jsp file in it but modify one line in the jsp and add it in the war file. Is it possible? If yes then how? Also can i modify an existing xml file by extracting it from a war file and then updating it again in the war after modification?

Let me know if any body have or knows the solution for this.

Regards,
Milton
 
Balan Raj
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My take wud be to write an ant script to extract the war to a temp folder, make the necessary change (is it a repeatable change?)
it back & do a ant copy to the Deplyoment folder.

Well, whether your servlet engine picks up the modified WAR is left to the implementation of the container. I dont think u woud want 'hot deploy' turned on in production.

The best bet would be to *restart* the engine again after the war is modified or when the XML file is copied again.

hth
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IF you mean to add new jsp/modified file to war file,

You can run ant again to packed war file again.

Example to packed war file with ANT

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I wanted to know how i can modify a line in an existing jsp page and put it in a war file.

No you can't. And its not something you should be using Ant for. Ant is a build and deployment tool, not a development tool.

Now you can manually change the file and have it included in the War file, which is the sort of work Ant will be expected to do 90% of the time, but you can't have Ant modify the file for you.


Also can i modify an existing xml file by extracting it from a war file and then updating it again in the war after modification

Now this you possibly could do, though in a fairly convoluted way. Ant can read in xml (you can include an XML file easily enough: we include a JBoss datasource file in the build to set JDBC properties for some SQL tasks). It has an XSLT which could transform the xml, and it shouldn't be difficult to call aa little script to save the result. However, again this is something you probably should not do, since it is using Ant for development.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Milton Quranda:
I wanted to know how i can modify a line in an existing jsp page and put it in a war file.
Others have already covered how you can extract the .war file, add stuff, and stuff it all into a .war file again.

However, I'd like to note that if this "modification" of the JSP is relatively simple, you might be able to use templating to accomplish what you're after. I.e. put a @placeholder@ into the original JSP file and insert the value into the template using an Ant variable while copying stuff with the <copy > task.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I second Lasse's suggestion of templating, but I'd take it one step further. Rather than changing the JSP iself, I'd put the variable portion in a properties file and modify that using the templating mechanism. That way, it is completely factored out of your JSP which merely gets the varying fragment out of the properties file.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
you can't have Ant modify the file for you


If the modification is mechanical in nature and needs to be done repeatedly (such as putting the build date at a specific place of a file, or replacing all leading tabs with spaces), it is something Ant *can* and *should* do for you.

If the already mentioned technique of copying a template using filters doesn't suffice, you could also take a look at the optional ReplaceRegExp task: http://ant.apache.org/manual/OptionalTasks/replaceregexp.html
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fair enough. I stand corrected.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic