Eclipse 更改项目文件位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1430836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:56:33  来源:igfitidea点击:

Eclipse change project files location

eclipse

提问by Luke

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.

我有一个 Eclipse 项目(Flex Builder),它的实际文件在驱动器上的位置发生了变化。当我启动 Eclipse 时,我可以看到列出的项目,但没有列出实际的文件。右键单击项目并选择属性将显示用于存储文件的旧路径,但我无法更改它。

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 项目的文件位置,在该项目创建后它将在其中查找文件?

回答by akf

You can copy your .classpathand .projectfiles 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.

您可以将您的.classpath.project文件复制到新项目目录的根目录,然后从文件菜单中选择“导入...”,然后选择“常规/现有项目到工作区”。在出现的对话框中,找到新项目目录的根目录并完成。确保在导入之前已从工作空间中删除旧项目。

回答by kerner1000

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

更简单:右键单击 -> 重构 -> 移动。

回答by sunil

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

此链接显示了如何编辑 eclipse 工作区元数据以手动更新项目的位置,如果位置已经更改或者您有很多项目要移动并且不想多次单击并等待每个项目,则此链接很有用: https: //web.archive.org/web/20160421171614/http://www.joeflash.ca/blog/2008/11/moving-a-fb-workspace-update.html

回答by parvus

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

现在有一个插件(自 2012 年底开始)可以解决这个问题:GitHub 上的gensth/ProjectLocationUpdater

回答by BeccaP

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

如果您将项目保存为存储库的本地副本,则最好从 git 导入。选择本地,然后浏览到您的 git 存储库文件夹。这对我来说比将其作为现有项目导入更好。尝试后者不允许我“完成”。

回答by Justin Wolf

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.

使用 Neon - 也发生在我身上。您必须在项目资源管理器中删除 Eclipse 版本(而不是从磁盘中)并将项目作为现有项目导入。当然,确保项目文件夹作为一个整体被移动,并且 Eclipse 元文件仍然存在,如@koenpeters 所述。

Refactor does not handle this.

重构不处理这个。

回答by Luise Fassbinder

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.

我移动了默认的 git 存储库文件夹,因此遇到了同样的问题。我编写了自己的类来管理 eclipse 位置并用它来更改位置文件。

        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:

这是我的 EclipseLocation 类:

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


}