How to copy modified files to several servers using ANT - eclipse

This script works good for the first server (server1), but it doesn't work for the second pass (server2) as at that point all 'modified' files are already flagged by the first pass.
<macrodef name="copythings">
<attribute name="todir"/>
<sequential>
<scp todir="#{todir}" trust="true">
<fileset dir=".">
<modified/>
<include name="cgi-bin/Application/" />
<exclude name="**/*.log" />
</fileset>
</scp>
</sequential>
</macrodef>
<target name="deploy">
<copythings todir="server1"/>
<copythings todir="server2"/>
</target>

I'd suggest copying the files from the fileset to a temporary folder first.
And copy to the server from that directory.
copy required files to a tempory folder
run the targets and use the temporay folder as base/filset for scp
delete the temporary folder

Related

How unjar every jar referenced in javac.classpath to a folder?

I have unjar ant task like below that was working until I changed classpath to include one more jar file. Wondering what the trick is to unjar every jar listed in javac.classpath. Basically it is breaking once javac.classpath has more than one jar file. I am Ant newbee. I am trying to figure out a way to enumerate every jar in javac.classpath and unjar it to build.classes.dir folder.
<unjar dest="${build.classes.dir}">
<fileset file="${javac.classpath}" >
</fileset>
</unjar>
if javac.classpath points to a folder then
<unjar dest="${build.classes.dir}">
<fileset dir="${javac.classpath}" >
</fileset>
</unjar>
will unjar all jar files in that folder.
if javac.classpath is a comma/semicolon separated list of file paths then you should change script a little bit to use filesets instead, like;
<?xml version="1.0" encoding="UTF-8"?>
<project name="Un-jar Demo" default="un-jar">
<fileset id="javac.classpath" dir="/path/to/jar/folder">
<include name="jar-file-1.jar" />
<include name="jar-file-2.jar" />
</fileset>
<target name="un-jar">
<unjar dest="test">
<fileset refid="javac.classpath">
</fileset>
</unjar>
</target>
</project>
of course, you can find some other ways to convert comma seperated list of files to a fileset

How to copy assets to build folder in FDT?

Flash Builder has an option to "Copy non-embedded files to output folder", which will copy resources loaded at runtime / not compiled into the application from source folders into the /bin-debug (build) folder.
How can I do this with FDT? Do I have to use an Ant task? If so -- I'm not familiar with Ant, how would I set this up?
I guess Ant's not so hard...the following did the trick:
<project default="copy">
<property name="from" value="./assets"/>
<property name="to" value="./bin/assets"/>
<target name="copy">
<echo message="Copying assets..."/>
<copy todir="${to}" >
<fileset dir="${from}"/>
</copy>
</target>
And I ran it via a Debug Configuration:

Using cvs add command in Ant to 'update' a module

Using ant through eclipse. What I'm trying to do is to add files or subdirectories to a module that already exists in the repository.
The problem is that I do not know (or shouldn't) what kind of files or subdirectories the script is going to find in the previously checked-out module.
Checksout module -> Modifies it (adding files, subsdirs) -> Add that module to the control version -> Commits
I'm making an approach like this:
<target name="checkout" >
<cvs cvsrsh="plink" cvsroot="${cvsroot}" package="${mymodule}" dest="${extract.dir}" command="checkout"/>
</target>
<target name="cvs_add" >
<cvs cvsrsh="plink" cvsroot="${cvsroot}" package="${mymodule}" dest="${extract.dir}" command="add -kb"/>
</target>
And getting this message:
[cvs] cvs add: in directory .:
[cvs] cvs [add aborted]: there is no version here; do 'cvs checkout' first
I also tried using ant-contrib's 'foreach', in order to navigate between files and subdirs, also not working.
I'd love a non-ant-contrib advice in this matter, or something not related with exec task. But I'm open minded.
I have came up with this solution:
<ac:for param="file">
<path>
<fileset dir="${mymodule}">
<!-- <include name="**/*.jar"/> -->
</fileset>
</path>
<sequential>
<local name="filename" />
<basename property="filename" file="#{file}"/>
<echo message="${filename}"/>
<cvs cvsrsh="plink" cvsroot="${cvsroot}" dest="${mymodule}" command="add -kb ${filename}"/>
</sequential>
</ac:for>
I finally surrender to ant-contrib. If anyone make a different approach, let me know.

.war file won't be updated

I have an old project, built using Google Web Toolkit in Eclipse. When I created it, I did the following steps, in order to get the .war file
GWT Compile Project
Run the following Ant script
<project name="The" basedir="." default="default">
<target name="default" depends="buildwar,deploy"></target>
<target name="buildwar">
<war basedir="war" destfile="The.war" webxml="war/WEB-INF/web.xml">
<exclude name="WEB-INF/**" />
<webinf dir="war/WEB-INF/">
<include name="**/*.jar" />
</webinf>
</war>
</target>
<target name="deploy">
<copy file="The.war" todir="." />
</target>
</project>
Get the .war file
Now, I had to change a port in my project, so I changed it in my code and did the same steps in order to get the .war
However, when I deploy my updated project in Tomcat, it still makes requests to the old port number (I found this reading catalina.out)
So, What can I do in order to get a new, fresh .war ???
You don't mention it, but did you change the ports in tomcat? I assume you did, but I just want to cover all possibilities.

In nant, how to delete contents of a directory, but not the directory itself?

Suppose I were scripting a deployment using nant on a Windows server to a file share: \\server\share. I want a nant script to delete all files from the share then copy in new files.
I have this code to delete the files, but I'm getting an error that it can't delete "\server\share". But I didn't want to delete the share, just the contents in it.
<delete>
<fileset basedir="\\server\share">
<include name="**/**" />
</fileset>
</delete>
Output:
BUILD FAILED
D:\code\xxx\xxx.deploy(177,8):
Cannot delete directory '\\server\share'.
Access to the path '\\server\share' is denied.
If I modified it to instead delete contents of a directory in the share, say \\server\share\somedir, it'll delete "somedir" without error. But still, I didn't want to delete the dir, just the contents. Is there a way?
This works for me - no workarounds required:
<delete>
<fileset basedir="\\server\share">
<include name="**\*" />
</fileset>
</delete>
You could introduce an "exclude" tag and exclude a dummy file. That'll leave the root folder intact.
I'm using the following:
<target name="clean">
<delete>
<fileset basedir="${DeployTo}">
<include name="**/*" />
<exclude name="**/aspnet_client/**" />
</fileset>
</delete>
</target>
Taking cue from nsr81, I was able to come up with this workaround that works for me:
<touch file="${DeployTo}/deleteme" />
<delete>
<fileset basedir="${DeployTo}">
<include name="**/**" />
<exclude name="deleteme" />
</fileset>
</delete>
<delete file="${DeployTo}/deleteme" />