74

I have an Eclipse project (Flex Builder) of which the actual files have changed location on the drive. When I start Eclipse I can see the project listed but there are no actual files listed. Right clicking the project and selecting properties will show me the old path where the files used to be stored but I can't change it.

How can I change the file location of an Eclipse project where it will look for the files after the project has been created?

Luke
  • 20,878
  • 35
  • 119
  • 178
  • 3
    See the accepted answer for this question: http://stackoverflow.com/questions/3479466/eclipse-moving-project-to-another-folder – Schmuli Oct 17 '12 at 11:50

7 Answers7

75

You can copy your .classpath and .project files to the root of the new project directory and then choose 'Import...' from the file menu, and select 'General/Existing Projects into Workspace.' In the resulting dialog, locate the root of the new project directory and finish. Make sure that you have deleted the old project from the work space before importing.

akf
  • 38,619
  • 8
  • 86
  • 96
  • 9
    if you import your relocated project in the same workspace, you will have to delete the old project first, otherwise Eclipse won't let you proceed with the import. – Jean-Pierre Schnyder Mar 11 '12 at 13:37
  • 8
    That is, delete the old project from the workspace (not from disk!) – Rose Perrone Mar 13 '12 at 14:04
  • I am doing this, and it finds my project just fine. However, clicking on "finish" (which is flashing like it's ready for me to do something) does not do anything. The dialog stays up; no error message. Is there something else that needs to be done? – BeccaP Sep 06 '13 at 22:37
  • I tried re-importing it from my git repository instead, and that worked. – BeccaP Sep 06 '13 at 22:40
  • 6
    WAY TOO COMPLICATED... just right click on the project -> refactor -> move. – Menefee Feb 21 '16 at 03:17
  • alas, if only there were a refactor option. – stu Mar 01 '16 at 19:24
  • 4
    @Menefee I believe your approach only works in case the files have _not yet_ changed location (because Refactor > Move will move the actual project files). What the OP wanted is to update the references to files that have already changed location. So in that case, it seems Eclipse still doesn't provide an easier solution than the accepted answer. – TanguyP Oct 09 '16 at 10:06
34

Much more simple: Right click -> Refactor -> Move.

kerner1000
  • 3,382
  • 1
  • 37
  • 57
23

This link shows how to edit the eclipse workspace metadata to update the project's location manually, useful if the location has already changed or you have a lot of projects to move and don't want to do several clicks and waits for each one: https://web.archive.org/web/20160421171614/http://www.joeflash.ca/blog/2008/11/moving-a-fb-workspace-update.html

sunil
  • 6,444
  • 1
  • 32
  • 44
  • Link mentioned is dead. Here is a cached version: https://web.archive.org/web/20160421171614/http://www.joeflash.ca/blog/2008/11/moving-a-fb-workspace-update.html – 11101101b Mar 27 '17 at 16:19
  • @11101101b Thanks for the update. I have changed the link in the original thread – sunil Mar 28 '17 at 06:09
11

There is now a plugin (since end of 2012) that can take care of this: gensth/ProjectLocationUpdater on GitHub.

parvus
  • 5,706
  • 6
  • 36
  • 62
  • 1
    This plugin works perfectly! This helps alot when you have moved stuff around on the disk :) – SebastianH May 30 '16 at 12:04
  • ProjectLocationUpdater worked like a charm. We had had only one extra step to complete before: since we were moving to different computer without same disk layouts, we had to move to another drive+location (from D: to C:\dev): we had to mount the old folder location to let eclipse find the old files using subst D: C:\dev. (On Linux/Max, a symlink would have done the trick) – Jidehem Oct 12 '17 at 09:06
  • Fantastic plugin. Since we have hundreds of projects in the workspace and some normally closed, used a working set to tag all the opened ones, then closed them, and selected all projects in that working sets to move them and then re-opened everything. – Alain P Jun 16 '22 at 14:50
1

If you have your project saved as a local copy of a repository, it may be better to import from git. Select local, and then browse to your git repository folder. That worked better for me than importing it as an existing project. Attempting the latter did not allow me to "finish".

BeccaP
  • 1,452
  • 1
  • 13
  • 19
1

I moved my default git repository folder and therefore had the same problem. I wrote my own Class to manage eclipse location and used it to change the location file.

        File locationfile 
            = new File("<workspace>"
                    +"/.metadata/.plugins/org.eclipse.core.resources/.projects/"
                    +"<project>/"
                    +".location");

        byte data[] = Files.readAllBytes(locationfile.toPath());

        EclipseLocation eclipseLocation = new EclipseLocation(data);

        eclipseLocation.changeUri("<new path to project>");

        byte newData[] = eclipseLocation.getData();

        Files.write(locationfile.toPath(),newData);

Here my EclipseLocation Class:

public class EclipseLocation {

    private byte[] data;
    private int length;
    private String uri;


    public EclipseLocation(byte[] data) {
        init(data);
    }

    public String getUri() {
        return uri;
    }

    public byte[] getData() {
        return data;
    }


    private void init(byte[] data) {

        this.data = data;   
        this.length = (data[16] * 256) + data[17];
        this.uri = new String(data,18,length);  
    }


    public void changeUri(String newUri) {

        int newLength = newUri.length();
        byte[] newdata = new byte[data.length + newLength - length];        


        int y = 0;
        int x = 0;

        //header
        while(y < 16) newdata[y++] = data[x++];

        //length
        newdata[16] = (byte) (newLength / 256);
        newdata[17] = (byte) (newLength % 256);

        y += 2;
        x += 2;

        //Uri
        for(int i = 0;i < newLength;i++)
        {
            newdata[y++] = (byte) newUri.charAt(i);
        }
        x += length;

        //footer
        while(y < newdata.length) newdata[y++] = data[x++];

        if(y != newdata.length)
            throw new IndexOutOfBoundsException();

        if(x != data.length)
            throw new IndexOutOfBoundsException();

        init(newdata);
    }


}
  • Thank you for this solution. This is the best approach, as it eliminates the possibility for human error. One detail that is helpful to note, however, is that "newUri" is: "URI//file:" + – Seva Safris Jun 18 '21 at 09:14
0

Using Neon - just happened to me too. You would have to delete the Eclipse version (not from disk) in your Project Explorer and import the projects as existing projects. Of course, ensure that the project folders as a whole were moved and that the Eclipse meta files are still there as mentioned by @koenpeters.

Refactor does not handle this.