I came up with a little hack to allow me to relatively easily share my Eclipse workspace using Dropbox. For those who don't know, Dropbox is a serivce that allows to you to automatically sync files like documents and photos across all your devices; computers, smartphones etc.
The major caveat of sharing a single Eclipse workspace across two different computers with two different operating systems is many of the workspace's settings are path dependent relative to the host operating system (think Windows \ versus OS X/Linux /). All these configurations are saved in the .metadata folder within the top of your workspace. I got around these issues by having two copies of this folder, one for the Windows based workspace and one for the OS X based workspace. A wrapper script copies the relevant folder before starting Eclipse and backs up a copy to save any new changes after Eclipse exits. This approach means you cannot have both Eclipse's running simultaneously on both machines otherwise the workspace's configuration may get corrupted.
Generally any changes made to a project on one machine will then be reflected on the other machine as well. Try to avoid using hardcoded paths when configuring the build paths for a project. Instead use Eclipse's User Libraries as they will be saved unique to each operating system's workspace settings.
Some people may say why bother with such a setup like this and instead just use a version control system. I am intending to also use Git for my projects but for tasks that aren't ready to be committed I think this Dropbox approach is fine to allow semi-seamless transition between two development machines.
Steps to Share an Eclipse Workspace On Windows and OS X Machines
These steps should be applicable to a Windows/Linux combination as well, substituting Linux in place of OS X.
- Install the same version of Eclipse separately on each machine.
- Sign up to Dropbox and install the client software on both computers.
- Make a folder in your dropbox for your workspace (e.g. C:\User\soliax\Dropbox\eclipse-workspace or /Users/soliax/Dropbox/eclipse-workspace). If Dropbox is setup properly, you'll only have to create it on one computer and then it will automatically be sync'd (created) on the other computer.
- Launch Eclipse on one of your computers, lets say Windows, and specify the location of your workspace folder. Optionally, you may setup workspace configurations at this time like installing any plugins, setting classpaths etc. Exit Eclipse when you're finished.
- With Eclipse closed, rename the .metadata folder to .metadata-windows.
- Repeat steps 4. and 5. but on your OS X computer and rename the folder to -osx, not -windows.
- Create a batch script on your Windows computer and save it as something like eclipse-dropbox.bat in the Eclipse installation folder. This is the wrapper script to start Eclipse. Copy/paste the following contents in.
Configure the WORKSPACE variable to point to your actual workspace folder in your dropbox.
@echo off REM Eclipse startup script for workspaces shared amongst two computers on Dropbox. REM Set path of your Eclipse workspace set WORKSPACE=%USERPROFILE%\Dropbox\Dev\workspaces\aroha echo Restoring Windows metadata for Eclipse... @call xcopy /HIEQRY "%WORKSPACE%\.metadata-windows" "%WORKSPACE%\.metadata" call eclipse.exe echo Backing up Windows metadata for Eclipse... @call xcopy /HIEQRY "%WORKSPACE%\.metadata" "%WORKSPACE%\.metadata-windows"
- If you want to pin this script to your Windows taskbar, try the following steps:
- Rename the *.bat script to *.exe. Then drop the icon on to your taskbar. For some silly reason Windows doesn't allow bat/cmd files to easily be pinned.
- Rename the script back to *.bat.
- Right-click the pinned icon, then right click the filename at the top of the menu (e.g. eclipse-dropbox) and choose Properties from the next menu.
- Rename the .exe extension to .bat.
- Change the icon as well if you wish.
- Create a shell script on your OS X computer and save it in the anywhere (I used /usr/bin) with the name of something like eclipse-dropbox. This is the wrapper script to start Eclipse. Make sure you use the command chmod +x in a Terminal window or something similar to make the script executable. Copy/paste the following contents in.This assumes Eclipse is installed in your Applications folder. Configure the WORKSPACE variable to point to your actual workspace folder in your dropbox.
#!/bin/sh # Eclipse startup script for workspaces shared amongst two computers on Dropbox. # Set path of your Eclipse workspace WORKSPACE=$HOME/Dropbox/Dev/workspaces/aroha # Copy the backup .metadata folder used for the OS X version of Eclipse to the actual working copy echo Restoring OS X metadata for Eclipse... rm -rf "${WORKSPACE}/.metadata" cp -Rfp "${WORKSPACE}/.metadata-osx" "${WORKSPACE}/.metadata" # Launch Eclipse open -W /Applications/Eclipse # Backup the working copy of .metadata for the OS X version of Eclipse when Eclipse closes echo Backing up OS X metadata for Eclipse... rm -rf "${WORKSPACE}/.metadata-osx" cp -Rfp "${WORKSPACE}/.metadata" "${WORKSPACE}/.metadata-osx"
- If you want to add the OS X shell script to your dock, use Automator to create an application that has a single job to execute a shell script and point it to the script you created in step 9. Then you can drop that application onto your dock.
Congratulation for the great post. Those who come to read your article will find lots of helpful and informative tips.
ReplyDeleteAcer - 10.1" Aspire One Netbook - 1GB Memory - 320GB Hard Drive - Espresso Black
Acer - 11.6" Aspire One Laptop - 2GB Memory - 320GB Hard Drive - Ash Black
Instead of putting the whole of Eclipse workspace in Dropbox, put only the Projects. In Projects too - you can put only the source in Dropbox and let the rest remain on some other local folder outside of the Dropbox folder. Something like this: http://redwoodr.tumblr.com/post/9062600303/using-dropbox-with-eclipse
ReplyDeleteWith this approach the overhead of copying over the .metadata folder each time you open Eclipse and then saving them back when Eclipse is closed can be gotten rid of!
Hello,Arun Mehra
Deletewondering your solution work for PC and Mac ? If yes, can you provide a more detailed steps
Thank you
Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.
ReplyDeleteComputer Repair Lakewood Ranch