在Eclipse项目中将名为“src”的外部源文件夹链接起来

8

这不是关于在Eclipse Java项目中链接源的问题

是否可以将名为“src”的外部文件夹添加到Eclipse中作为源文件夹。 问题在于保持外部文件夹名称为“src”,而不是任何其他名称; 为此,我尝试从标准的Eclipse Java项目中删除src和bin文件夹,然后尝试“链接源”,但无法实现。

我还有其他方法可以实现吗?

也就是说,使Eclipse Java项目的src实际指向名为“src”的外部文件夹? 输出文件夹“bin”也存在类似的问题。

System Information
OS: Windows 8, 32 bit
Eclipse: 3.7

感谢您的选择。

2
链接源有什么问题? - ᴇʟᴇvᴀтᴇ
@aetheria 当源文件夹已经存在时,我无法添加另一个名称为src的源文件夹,即使我删除原始src文件夹并尝试添加外部src文件夹,它仍然无法识别。还注意到,即使我删除原始src文件夹,.classpath文件也不会改变,并且仍然抱怨缺少源文件夹。 - Ayusman
3个回答

9
您需要使用Eclipse从项目配置中删除现有的源文件夹,然后从文件系统中将其删除,然后可以将外部链接的源文件夹添加为“src”。
步骤如下:
1. 右键单击项目,选择“属性...”。 2. 点击“Java Build Path”,然后点击“源”选项卡,显示构建路径上的源文件夹列表。 3. 选择“yourproject/src”,然后单击“移除”按钮。这将从项目(和.classpath文件)中删除它。 4. 退出该对话框并物理删除该文件夹。 5. 回到该对话框,这次单击“链接源代码...”。现在应该可以正常工作了。

5
为了与外部文件夹建立链接,如果已经存在与“src”相同名称的文件夹,则需要重命名该文件夹或将其删除。之后,您可以使用以下任一方法之一与外部文件夹建立链接: 方法1-(通过代码手动创建链接):
1. Open the .project file from root folder of your workspace.
2. Include the below code with your file path:
    <linkedResources>
        <link>
            <name>folder_name_list_in_your_project</name>
            <type>2</type>
            <location>folder_path_to_include</location>
        </link>
    </linkedResources>
3. Save the file and refresh the project to include the external folder in your project.

方法二 - (通过UI手动创建链接):

1. Right click the project, select "Build Path -> Configure Build Path".
2. Choose "Source" tab.
3. Click "Link Source" button.
4. Click "Browse" to choose the folder.
5. Enter the folder name in "Folder name" field to list the external name in your project.
6. If you need to add the pattern for include and/or exclude file, click "Next" and enter the pattern. Then click "Finish".
7. Otherwise click "Finish".

这对我有效,希望我的步骤也能帮助到您。


0

这个方法有点丑陋,但你可以在文件系统中创建一个硬链接。在Windows命令行中,使用mklink /H src d:\path\to\external\src

我知道以下内容可能不太有用,但是:考虑采用不同的方法。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接