The Developer's Tidbit

June 9, 2009

Implement Dreamweaver like FTP Upload On Save function to Eclipse without the need for ANT

Filed under: eclipse — Ben @ 9:01 pm
Tags: , , , ,

One familiar problem with using Eclipse for web development is that it expects developers to run or compile sources on their local machines. Now this expectation is not really appropriate for many situations including HTML development where you develop on remote or virtual test servers. So we are going to customise Eclipse so it will automatically upload a file to a test server whenever it is saved, after editing.

Firstly this technique requires the use of the free Aptana plug-in for Eclipse. For those who don’t know, Aptana is a very functional IDE plug-in for Eclipse that puts a focus on web based development.

Assuming Aptana is installed and up and running we can go on. Firstly we need to change the Eclipse perspective to Aptana so we can be certain the correct menu options are available while you follow this tutorial.

The first thing you need to do is create a new folder ‘scripts’ in the root of the project where you wish to enable Upload Current File On Save. You can do this by selecting the project and then right-click, New > Folder.

Create folder

Now with your newly created scripts folder, right-click it. New > JavaScript File. With the New JavaScript File dialog save the script file as upload_current_file_on_save.js.

New JavaScript File

Once created, select from the Eclipse menu select Window > Open Perspective > Aptana

From the Eclipse menu select Window > Show Aptana View > Scripts

This should bring up a new window listing all the available Aptana customized scripts. In the Scripts dialog, scroll down to the bottom to the folder ‘Synchonize’. Look for, select and then right-click over the script ‘Upload Current File On Save’. Select ‘Edit Script’.

Scripts dialog

Select the body of the script [Ctrl A] and copy it to the clipboard [Ctrl C]. Open the blank upload_current_file_on_save.js you created earlier, paste the content of the clipboard into the file [Ctrl P]. Then save the modified file either with [Ctrl S] or using the Eclipse menu, File > Save.

upload_current_file_on_save.js

Now we need to modify the script as by default it is disabled. On line 5 where it says * Menu: Synchonize > Upload Current File On Save; replace the word Synchonize to the name of your project or website. Save the changes. You should be able to test that everything is okay by going to the Scripts menu, there should be a sub-menu item with the name of your project or website with a Upload Current File On Save option.

Scripts Menu

Now back in the script window, go to line 12 which says // * Listener: commandService().addExecutionLister(this);
Remove the comments which are the two forward slashes, //. Select and cut the whole of line 12 and insert it to line 5 so it now sits above the *Menu: … item as shown below. Again save the file and you cna now close the Script edit tab.

Modified Script

Now the script is complete, we need to setup a FTP account.

In the Eclipse menu select Window > Show Aptana > View > Sync Manager

Right-click on Sync Manager and select Add Site Connection
A new dialog will come up, Create Site Connection.
Give a short but meaningful Connection name.
In the Path section, change the Local: from File to Project.
Browse for and select your project.

Now we add the FTP testing server details. In the same dialog, under Remote: + Select remote server, select Add New FTP (or SFTP, FTPS). Enter your site details and press Okay. Back in the Create Site Connection dialog, also press Okay.

Create an FTP connection

Now we are almost there all we need to do now is select the new connection to make sure it is used as default whenever we save a file within the project.

Right-click your project name, under the Project tab. Select Properties at the bottom of the right-click menu. In the Properties dialog click the Synchronization option near the bottom of the options. Change the Default Synchronization Connections to the one you previously created and make sure the Use Connection As Default checkbox is checked.

Default sync
Congratulations you now have enabled automatic uploads on save for your Eclipse project!

4 Comments »

  1. Thanks for posting this, and for having it posted in the Aptana blog. It works as advertised. I think it works best when any synch connections/FTP connections are deleted – initially had issues getting the connection to show in Project > Properties > Synchronization connection list.

    Comment by Mike-sf — August 24, 2009 @ 1:36 am | Reply

  2. Thank you! Was browsing the aptana forums trying to get it to work, but this post is the one!

    You might consider adding that you also need to remove the text behind the command:
    // Add * Listener: commandService().addExecutionListener(this); [to the top of this file to enable it]

    Even though it’s quite obvious ;)

    Comment by Christoffer Wallenius — August 31, 2009 @ 12:08 pm | Reply

  3. thank you,
    i have done all the above until where you say: “Now the script is complete, we need to setup a FTP account.”
    you say to select Window > Show Aptana > View > Sync Manager.

    But in my list there there are some views (in Aptana) but not the Sync Manager (or any similar).

    am i doing something wrong?
    all the above procedure was successfully done without any problems.

    thank you for your help

    Comment by Nikos — November 12, 2009 @ 2:27 pm | Reply

    • This article was written in June 2009, so it was intended to work with Aptana 1.6, not the 2.0 edition that was released last week. This new revision probably does not work with this write-up.

      Comment by Ben — November 12, 2009 @ 4:36 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.