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

后端 未结 5 1585
独厮守ぢ
独厮守ぢ 2020-12-11 04:32

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 locat

相关标签:
5条回答
  • 2020-12-11 05:01

    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.

    0 讨论(0)
  • 2020-12-11 05:02

    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:
    
    0 讨论(0)
  • 2020-12-11 05:05

    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.

    0 讨论(0)
  • 2020-12-11 05:12

    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

    0 讨论(0)
  • 2020-12-11 05:15

    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.

    0 讨论(0)
提交回复
热议问题