Deploy only your JSP files with this Ant build task

A lot of times when you're working on a Java web application you only need to deploy your JSP files. This happens, for instance, when you're just editing the JSP files to modify the look and feel of your web application. In cases like this there's no need to rebuild your entire application, deploy it, then restart your application server (Tomcat, Glassfish, JBoss, whatever).

Instead, all you have to do is just deploy your JSP files, and any support files they use, like HTML files, CSS, JavaScript, or image files. To that end, here's the source code for an Ant task I use that deploys only my JSP files (and all other "visual" files, like HTML, CSS, JavaScript, and image files:

<!-- JSPs ONLY -->
<target name="jsps">
  <echo>=== DEPLOY JSP'S ===</echo>
  <!-- trying to be explicit about what i put out there -->
  <copy todir="${war.deploy.dir}/${jsp.dir.name}">
    <fileset dir="${pages.dir}">
      <include name="**/*.jsp"/>
      <include name="**/*.html"/>
      <include name="**/*.css"/>
      <include name="**/*.gif"/>
      <include name="**/*.jpg"/>
      <include name="**/*.png"/>
      <include name="**/*.js"/>
    </fileset>
  </copy>
</target>	

How to run this Ant JSP-only task

To run this Ant task just type

ant jsps

in your build window, or if you're using a tool like Eclipse, IntelliJ, NetBeans, JBuilder, etc., just click the jsps target in your UI.

If everything is configured properly this task will deploy all your visual files from a directory identified by the variable ${pages.dir} to a destination directory identified by the variable named ${war.deploy.dir}/${jsp.dir.name}.

Of course feel to modify this code and use your own variable names. I just wanted to show how I do this with some real world Ant build script code.