Jun
15
The more I play with ANT the more I kick myself for not looking into it earlier. This past weekend I was playing with some different ways to run builds and one of the things I ran into is having ANT ftp files to your different servers as you deploy your application from dev to qa, staging and production.
One of the first things you need to do is add two jar files to your ANT installation's lib folder from Jakarta Commons Net and Jakarta-ORO. They are commons-net.jar and jakarta-oro-2.0.8.jar.
After you have these two files, create a target like the one below named "ftp.deploy" in your build.xml file. See sample below:
<!-- set global properties for this build -->
<!-- hd path to application -->
<property name="application.dir" value="D:\inetpub\alogix\" />
<!-- ftp server to move files to -->
<property name="ftp.server" value="www.alogix.net" />
<!-- directory in server to move files to (root relative) -->
<property name="ftp.remotedir" value="/" />
<!-- filesets -->
<fileset id="fileset.exclude" dir=".">
<exclude name="*build.xml" />
<!-- use this if you need to exclude a folder (uncomment line and change folderName) -->
<!-- <exclude name="**/[folderName]/**" /> -->
<!-- use this if you need to exclude a file (uncomment line and change filename & extension -->
<!-- <exclude name="*[filename].[extension]" /> -->
</fileset>
<!-- targets -->
<target name="ftp.about">
<echo message="Using FTP in ANT example." />
<echo message="By: Phill Nacelli" />
<echo message="www.phillnacelli.net" />
</target>
<target name="ftp.help">
<echo message="usage: ftp.deploy" />
</target>
<target name="ftp.deploy">
<input message="Please enter ftp server username:" addproperty="ftp.username" />
<input message="Please enter fpt server password:" addproperty="ftp.password" />
<ftp action="send" server="${ftp.server}" userid="${ftp.username}" password="${ftp.password}" remotedir="${ftp.remotedir}">
<fileset refid="fileset.exclude" />
</ftp>
</target>
</project>
Notice that nowhere in the build.xml file you see any username and password written. Instead of storing it on the file as a property we actually prompt the user for it when running the ftp.deploy target. This ensures that you can distribute your build file without compromising security.
If you use any versioning systems, notice that in the fileset.exclude we did not enter anything to stop the system files that they embed in your project (ie. ".svn" folder for Subversion, "vssver.scc" for VSS), that's because they are already excluded by default (see Default Excludes section on this page).

Phill Nacelli has been developing software for over 9 years, and have been using ColdFusion since version 4.5. He has engineered and developed multiple web based applications for the federal government, non-profit association/education market and enjoys playing with the latest in programming techniques, frameworks and development tools. He currently holds a position as Software Architect at




java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient
I am using Eclipse 3.2. Any ideas on how to solve this?
Hope you can help,
Erik-Jan
Try the following:
1. In Eclipse go to Windows > Preferences...
2. In the left tree navigation control, expand Ant and click on Runtime
3. In the right pane select the Classpath tab and Click on Ant Home Entries, this will show all the jar files used by ANT in Eclipse.
4. Check if the two jar files show up in there, if not click on Add External JARs...
5. Select the two jar files and see if they show up in the list.
6. Click on Apply button and just to be sure restart your Eclipse.
Give it a shot.. let me know how this works for you. I'll be happy to help you troubleshoot this further.
Cheers..
Just to confirm that modifying the ANT Classpath under Preferences does work just fine.
Thanks for the ftp task explain.
From Spain, Javi.
Bye!