Tuesday, March 9, 2010

Coding anywhere with Dropbox Eclipse Maven

There are several Java projects that I like to work on when I have some free time. My pain is, the “free time” is from different locations, different computers and different Operating Systems. In work, my computer is a Dell PC installed Windows Vista. At home, I use a PC with Windows 7 and my sweet heart, Macbook Air with Snow Leopard.

The precious “free time” cannot be wasted on copy paste project via USB stick. And you know, Mac keeps generating .DS_Store, .trash files which are annoying. Then I started to use Subversion, commit my changes before I left company and update when I get home. Yes, as you predicted, what if the codes haven't passed test or even with compile errors? Therefore, subversion does not fit my multi-locations development scenario.

I have heard DropBox for a long time and I found it's perfect for me to code in different computer. I am Java developer, Eclipse and Maven are the most frequently IDE and build tools I used. A Maven's project in Eclipse workspace looks like that:

The key to use DropBox to synchronize maven project between different computers is to copy the three folders I selected(src,sql, pom.xml) into DropBox folder and create symbolic link to those in your eclipse workspace. The rest folder or file is only for your local computer and should be avoided to synchronize(Similar to import project into Subversion repository). I will show you how to do it in Windows and Mac.
In Windows
The symbolic link requires another software. I recommend Link Shell Extension . It provides enough documents for you to do the symbolic link.
Firstly of all, copy the Maven project into your DropBox folder (only src, sql, pom.xml) either in Mac or Windows.
Secondly, create a folder in your eclipse workspce. Then do the symbolic link.
In Windows,
open DropBox folder and browse to the project folder, right click on "src" folder, select "Pick Link Source".

Go into your eclipse workspace project folder, right click, select "Drop As..."->"SymbolicLink". Do the same to "sql" folder if you have.

The "pom.xml" file is a litte bit different, after you selected By "Pick Link Source", simply select "Symbolic link".
In Mac, life is much easier, open "Terminal", "cd" into your eclipse workspace folder, and use the following command:

ln -s ~/Dropbox/myproject/src src
ln -s ~/Dropbox/myproject/sql sql
ln -s ~/Dropbox/myproject/pom.xml pom.xml
Now projects in all your computers will linked to the project in DropBox's cloud. The DropBox will synchronize your project for you between different places.

Fire up "cmd" or "terminal", "cd" into your project folder within eclipse workspce,

Use "mvn eclipse:eclipse" to generate eclipse project descriptor and import it into your eclipse.
Note: In Mac, maven eclipse plugin might not work well with symbolic link folder. The source folders are pointed to the incomplete path to Dropbox. It's not hard to fix maully.
Wherever you modify your code, the other place will be synchronized. Amazing,Happy Coding:)

8 comments:

Eugene Ryzhikov said...

Why would you use remote source management instance such as SVN, GIT etc? You going to get much from it!

Ke Cai said...

Hi, I have mentioned at begining:

Therefore, I started to use Subversion, commit my changes before I left company and update when I get home. Yes, as you predicted, what if the codes haven't passed test or even with compile errors?


Subversion is supposed to store code passed all test. If the code has error, it's not good idea to commit it into SVN.

Eugene Ryzhikov said...

Then you have to use Git or Mercurial (instead of SVN), where you work with your own local repository and then push your change sets to the remote one.

gorlok said...

You can use even SVN doing a branch for your ongoing work.
"Subversion is supposed to store code passed all test" it's not true. You can do anything what you want with any VCS.
Some people found Git/Mercurial better for merging, but I havn't found big problemns with svn anyways, and I heavyly branch/merge.

Ke Cai said...

yeah, you are probably right about SVN. Compare with "heavyly branch/merge", I think Dropbox makes our life easily since there is nothing you have to do.

I still hold a view about "Subversion is supposed to store code passed all test", not a repository for file sharing and synchronization.

Ashish Jain said...

It does seems to be good idea. But I wonder how sync works in all scenarios, specially, in case of you delete on one m/c or rename it. Have you faced any problem around it?

Ke Cai said...

No problem at all. Have a try, DropBox even tracks change for you.
If you regret, you can find previous versions listed in DropBox.

Krige said...

It seems the "SymbolicLink" option is available for Windows Vista and 7 only. Do you know any way to make it work in Windows XP too?