Portable Eclipse - eclipse

I'm trying to port my entire 'workspace' to a USB key (including the Eclipse executable) so that I can carry my work anywhere with me and work off the key directly.
My directory hierarchy is similar to this:
/workspace/eclipse - Where my current eclipse binary is stored
/workspace/codebase - Where I keep the root of all my eclipse projects
/workspace/resources - Where I keep all project files (images, docs, libs, etc.)
It all works perfectly fine on one system. But when I change over to another system, the USB key gets mounted on another drive. For example, on my laptop, I get 'E:\', on my PC, I get 'K:\' and at work I get 'F:\', etc, etc.
This means that because Eclipse (for 'some' reason) seems to only use full path names (including driver letters) in every single one of its configuration files (such as .classpath), nothing ever works when I want to work on another system.
I put a 'libs' directory in the base of every project and populate it with its dependent JAR files. Why doesn't it use relative names instead, so that I could specify something like "../../libs/log4j.jar"?
Anyone know how to fix this problem? Does anyone know of a workaround for this?
Update: 2010.11.09
I've recently discovered Dropbox, which allows you to sync your files online and across your computers automatically with extreme ease. It includes 2GB of free space and you can upgrade to much more if you want (for a yearly fee).
I installed it on my two laptops, my two PC's, my Linux server and my Android phone and then I created a 'workspace' directory within the 'My Dropbox' folder. From the 'workspace' directory, I then installed Eclipse and created/configured all my projects as usual. I can literally work from any computer and everything always stays perfectly in sync. This is way better than any USB key functionality and its hassle!

Have you tried using Eclipse Portable?
The only thing to keep in mind is that when switching the workspace, you need to remember to give it a relative path (like ../../Data/workspace).

You could use the dos command subst to get a consistent drive letter by creating a new virtual drive letter (say x:) that maps to your Eclipse folder on your usb drive, and then make all the config paths reference the drive x:
You could make a little batch file on the usb drive that you click on to create the drive x:
C:\>help subst
Associates a path with a drive letter.
SUBST [drive1: [drive2:]path]
SUBST drive1: /D
drive1: Specifies a virtual drive to which you want to assign a path.
[drive2:]path Specifies a physical drive and path you want to assign to
a virtual drive.
/D Deletes a substituted (virtual) drive.
Type SUBST with no parameters to display a list of current virtual drives.

You could also remap letter for your USB stick in Windows Disk Management (subitem in Computer management) to be smth like 'U:'.
Once done, it will be re-assigned to same stick every time you plug it. Not very universal, since your user need rights to access this setting first time, but it could help in some different scenarios.

You can always use Ant to build your programs, with Ant you can have relative paths... Plus you can also use Ivy to track dependencies in Ant, I do that in every project that I have.

Another alternative is to manually edit your .classpath files to contain relative paths.
It is a bit of a hassle, though, as you'll have to manually update the files whenever Eclipse changes them.

Related

.emacs.d folder equivalent for eclipse

I want to know if there is any place where eclipse stores all my configurations so that only the config files can be ported across different machines(even different OS's)
If I spend my time customizing eclipse on my desktop , spending the same amount of time on every machine I work on is a no brainier. I was hoping eclipse stores its files in some directory in home directory(~/.emacs.d on linux/mac mainly, but use windows often as well) just like emacs does. With this I can easily put all my configurations under VCS and get exactly the same look and feel on every machine. I have done this for emacs actually and it works great. Like this https://github.com/anooprh/dotfiles/tree/master/emacs.d
I could not find anything like that for eclipse. The closest I could find was .eclipse folder in home directory
[user#localhost .eclipse]$ pwd
/home/user/.eclipse
[user#localhost .eclipse]$ ls
org.eclipse.platform_4.4.1_1473617060_linux_gtk_x86_64 org.eclipse.platform_4.4.1_1756587775_linux_gtk_x86_64
I dont know what these two directories. Inside that there were was a configuration directory as well, but could not find anything useful.
I want to know from people who have been using eclipse for some time as to how they manage to port their config files from one machine to another.
Thanks in advance

how to use eclipse workspace on different computers

I have 3 developer machines (office desk, office laptop and home laptop) and I would like to keep my eclipse workspace and projects on usb drive and use it on all 3 computers... is this possible and how?
Though it is possible by indicating the folder on your usb to be your workspace, I'd recommend using version control if you have access to some server. This way you can work on your projects anywhere, have constant backup, and keep track of the changes.
Try using dropbox folders for your workspace (with their packrat feature its even better). That will keep all your files up to date :D.
Yes it is. Copy the workspace folder to your usb drive and open the workspace from any Eclipse installation you want to.
By the way, it may be a better idea to use a version control system. Sure, you'd have to synchronize your workspace every time you make a change in the code and commit it, but usb drives can get lost, or stolen, and I'm sure you wouldn't want to lose all of your projects if you lost your usb drive.
It's possible. Change your workspace to point to your shared drive. This is easier on OS's like linux as you can mount the USB drive to a specific directory.
Or, do what I do and copy the workspace directory for specific projects from one machine to another. This was covered here :
How to share eclipse configuration over different workspaces

How to use relative paths for projects added to an Eclipse workspace?

I am working on some Eclipse projects that are stored on a USB key. I have added them to a workspace whose root folder is also on the USB key, but the projects are not located directly into this directory. As a result their absolute paths are written in the .projects folder of the workspace.
This raises problems when I use the key on several computers, because the drive letter assigned to the USB key is not always the same (and I do not want to assign a specific letter to it on all computers). Eclipse cannot open my projects when the drive letter differs from that of the USB key at the time I added the project to the workspace.
Is there a solution to this problem ? Specifically, is there a way to make Eclipse add projects to a workspace by using their relative path from the workspace folder ?
Its really not that hard. You just have to assign a new variable that points to WORKSPACE/..;. For example, you can use the Forge Minecraft modder pack - it has a workspace that is immediately ready no matter what machine downloads it, where you place it or even if you move it.
Download this:
http://files.minecraftforge.net/minecraftforge/minecraftforge-src-1.6.2-9.10.0.789.zip
And then unzip it and run install.bat/cmd. Then check the contents of forge/mcp/eclipse/Minecraft/{.project,.workspace} to see some examples.
I've got my workspace working on github like this.
In my experience it will break at some time if you try to "hack" the metadata of eclipse.
Consider the substcommand in windows (As you mention drive letter I assume windows)
create a bat file containing
subst N: .
Running this will mount the current dir as N: So You can place this on the usb drive, and run that prior to running eclipse, then You will always find the same content on drive N:
To remove the mount do
subst /D N:
You might consider making a bat file that mount N:, start eclipse and after eclipse exit unmount N: something like
startMyProject.bat:
subst N: .
N:/eclipse <yadayada options>
subst /D N:
The short answer is that you cannot do it without hacking your workspace metadata (under [workspace.dir]/.metadata). Eclipse workspaces aren't designed to be portable and even though you are not physically moving your workspace, you are in effect moving it by changing drive letters.
I'd recommend trying to find a way to have your projects under workspace.dir. Not guaranteed that you will not have problems that way, but may improve your odds. Depending on what features of Eclipse you use, you may very well end up with other types of absolute paths in your workspace metadata.
This question is kinda old, but there's an entirely different approach: You can create a Junction from the Folder where Eclipse expects the Project, for example E:\foo\workspace\myproject and link it to where the project lays, for example E:\bar\myproject.
A Junction essentially means that you can access the same folder through 2 different paths, thus you don't need to worry with the weird relative path limitations of Eclipse. To create it easily and fast, I recommend you to get Link Shell Extension
I haven't tried this myself, but this might work. Try:
Add your source folder as linked resource & remove previous definition:
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.user/tasks/tasks-45.htm
Close eclipse and find your project folder in your workspace (ex: C:\Documents and Settings\username\workspace\yourproject\) Replace absolute paths in files .project & .classpath with relative paths.

Configuring Eclipse .classpath for two different paths for the same entry

I'm wondering if there is a way (in Windows 7) to make some sort of mapping of drives so that sometimes you find the files in a network drive and sometimes you find them in a local map?
-And to be able to easily switch between those two.
The reason I want to do this is that I want to be able to work (as a developer, using Eclipse for Java) partly at work, where I have certain library files in a network drive, and partly on the train, where I can't access the internet, so then I need to have those library files in a local map on my laptop.
In my Eclipse projects I point out those library files using their whole file paths, and it's a lot of files and a lot of projects and I don't want to be forced to change every single filepath just because I'm temporarily working from a train.
I'm thinking that it would be great if I could map the same drive (say, drive "S"), so that it could either point to the place at the network or to a local map, depending on some easy switching.
How would you configure your environment in order to not change anything in your Eclipse project?
You could try SUBST
SUBST, substitute a drive letter for a network or local path. It basically creates a virtual drive with a local or a global (making this phrase sound more programmer-like) path.
Syntax:
SUBST drive_letter: path //set the virtual drive path
SUBST drive_letter: /D //delete the drive
Another site!
You could reference a those two paths on the same virtual drive with "subst".
That way, 'S:\' could refer to two different paths depending on your current workstation.
On workstation1:
subst S: c:\path1\to\files
On workstation2:
subst S: c:\path2\to\files
On your .classpath in both cases:
S:\yourFiles
Thank you for your answers, but I didn't really like 'subst', since the removal of the drive seemed to "remove the drive letter", so it couldn't be used again until I had restarted my computer.
A colleague of mine had found a solution that was just what I was looking for: Two VBScript files: One for changing the drive mapping to a local (but shared) folder, and one for changing to the remote folder. The files look like this:
Set objNetwork = CreateObject("WScript.Network")
on error resume next:
objNetwork.RemoveNetworkDrive "N:" , true, true
objNetwork.MapNetworkDrive "N:", "\\MYCOMPUTER\SHARED"
-This code is for changing to the local folder, but in the other file you just change the file path to the remote one.
Maybe this can help someone else who's having the same problem.

VS2008 Setup Project - Portability

When I add a file to my setup deployment project, Visual Studio won't allow me to edit the "SourcePath" to resolve an environment variable like $(DLL_PATH). It adds the file with the source path on my local machine and builds fine locally. When the same project is built on another machine, it won't work unless that machine also has the exact same path to files needed.
I want the SourcePath to resolve the $(DLL_PATH) so as long as a machine has it defined correctly the MSI package will build fine.
Not sure about the subst, since I have no control over what the other build machine looks like. If I try to assign a known directory to a virtual drive, it could possibly fail right?
Your best bet is to use subst.exe or a junction point to create a virtual directory. See here for information on junction points. Subst.exe simply creates a virtual drive letter. Put all of the deployable files in some directory tree with well-defined, constanct sub-paths, and make the root of that tree a junction point or virtual drive.
Actually what I did was setup a script.cmd to run after my project output is built to copy the dependencies to a folder that is relative to the actual project folder from the declared $(DLL_PATH). The setup project actually uses relative paths to the project, not absolute ones. So this works no matter what the build machine looks like. Then a script to remove this folder at the end.