aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Modification of JSP file using ANT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Modification of JSP file using ANT" Watch "Modification of JSP file using ANT" New topic
Author

Modification of JSP file using ANT

Milton Quranda
Greenhorn

Joined: Sep 17, 2002
Posts: 7
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

Joined: Aug 26, 2003
Posts: 74
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

Joined: Jul 04, 2003
Posts: 1312
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



SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Fair enough. I stand corrected.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Modification of JSP file using ANT
 
Similar Threads
How to create new context or Modify
How to implement in EJB
unable to extract war file after restart of tomcat
How to add Attributes to a existing XML File.
Loading war file in tomcat