Eclipse change project files location

Eclipse

Eclipse Problem Overview


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?

Eclipse Solutions


Solution 1 - Eclipse

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.

Solution 2 - Eclipse

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

Solution 3 - Eclipse

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

Solution 4 - Eclipse

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

Solution 5 - Eclipse

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".

Solution 6 - Eclipse

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

Solution 7 - Eclipse

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLukeView Question on Stackoverflow
Solution 1 - EclipseakfView Answer on Stackoverflow
Solution 2 - Eclipsekerner1000View Answer on Stackoverflow
Solution 3 - EclipsesunilView Answer on Stackoverflow
Solution 4 - EclipseparvusView Answer on Stackoverflow
Solution 5 - EclipseBeccaPView Answer on Stackoverflow
Solution 6 - EclipseLuise FassbinderView Answer on Stackoverflow
Solution 7 - EclipseJustin WolfView Answer on Stackoverflow