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?

1

7 Answers 7

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.

7
  • 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. Mar 11, 2012 at 13:37
  • 8
    That is, delete the old project from the workspace (not from disk!) Mar 13, 2012 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 6, 2013 at 22:37
  • 6
    WAY TOO COMPLICATED... just right click on the project -> refactor -> move.
    – Menefee
    Feb 21, 2016 at 3:17
  • 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 9, 2016 at 10:06
34

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

5
  • because in this case simpler is better.
    – natedennis
    Jun 23, 2015 at 17:37
  • @Luke please accept this! It's more current. Works great and seamless!
    – ADTC
    May 25, 2016 at 17:03
  • Really the better answer ;-)
    – GhostCat
    Jul 26, 2017 at 10:35
  • Don't have "refractor" on right click either, but I can find it in the "refractor" menu when in "Sript Explorer", but the "Move.." is grayed out. :'(
    – e-motiv
    May 27, 2018 at 18:47
  • Use the "package explorer" view rather than the "project explorer" view to get the refactor command.
    – Boann
    Sep 19, 2018 at 21:45
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

2
11

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

3
  • 1
    This plugin works perfectly! This helps alot when you have moved stuff around on the disk :)
    – SebastianH
    May 30, 2016 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, 2017 at 9: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, 2022 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".

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);
    }


}
1
  • 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:" + <absolute_path_to_new_location_of_project> Jun 18, 2021 at 9: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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.