Java 在 Eclipse 项目中链接名称为“src”的外部源文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20146646/
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-08-12 23:29:49  来源:igfitidea点击:

Linking external source folder with name "src" in an eclipse project

javaeclipse

提问by Ayusman

This is NOT a question about linking source in eclipse java project

这不是一个关于在 eclipse java 项目中链接源代码的问题

Is it possible to add an external folder named "src" in eclipse as the source folder. The problem here is to keep the external folder name as "src" and not any other name; to do that I tried deleting src and bin folder from the standard eclipse java project and then tried to "Link Source" but that does not work.

是否可以在eclipse中添加一个名为“src”的外部文件夹作为源文件夹。这里的问题是将外部文件夹名称保留为“src”而不是任何其他名称;为此,我尝试从标准 eclipse java 项目中删除 src 和 bin 文件夹,然后尝试“链接源”,但这不起作用。

Is there any other way I can make this happen?

有没有其他方法可以让我做到这一点?

That is make the Eclipse java project's src actually point to an external folder named "src"? Similar issues with the out put folder "bin" as well.

那是让 Eclipse java 项目的 src 实际上指向一个名为“src”的外部文件夹吗?输出文件夹“bin”也存在类似问题。

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

Thanks.

谢谢。

采纳答案by ???v?т?

You need to use Eclipse to remove the existing source folder from the project configuration, then delete it from the file system, then you can add the externally linked source folder as "src".

您需要使用 Eclipse 从项目配置中删除现有的源文件夹,然后从文件系统中删除它,然后您可以将外部链接的源文件夹添加为“src”。

  1. Right-click on the project and bring up "Properties..."

  2. Click on "Java Build Path" and then the "Source" tab to show a list of the source folders on the build path.

  3. Select "yourproject/src" and click the "Remove" button. This will remove it from the project (and the .classpathfile).

  4. Come out of it and physically delete the folder.

  5. Go back to that dialog box and this time click "Link source...". It should work now. It works for me.

  1. 右键单击项目并调出“属性...”

  2. 单击“Java 构建路径”,然后单击“源”选项卡以显示构建路径上的源文件夹列表。

  3. 选择“yourproject/src”并单击“删除”按钮。这将从项目(和.classpath文件)中删除它。

  4. 从它出来并物理删除该文件夹。

  5. 返回该对话框,这次单击“链接源...”。它现在应该可以工作了。这个对我有用。

回答by f1sh

It is somewhat ugly, but you can create a hardlink in your filesystem. In the Windows command line, use mklink /H src d:\path\to\external\src.

这有点难看,但您可以在文件系统中创建硬链接。在 Windows 命令行中,使用mklink /H src d:\path\to\external\src.

I know that the following will hardly be useful, but: Think of a different approach.

我知道以下内容几乎没有用,但是: 考虑不同的方法。

回答by Srinivasan.S

To make link with external folder, we need to rename the folder if any folder already exists with same name like "src" or better delete that folder. After that you can make link with the external folder using the anyone of the following method:

要与外部文件夹建立链接,我们需要重命名文件夹,如果任何文件夹已经存在,如“src”或更好地删除该文件夹。之后,您可以使用以下任何一种方法与外部文件夹建立链接:

Method: 1 - (Make link manually via code):

方法: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.

Method: 2 - (Make link manually via UI):

方法:2 - (通过 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".

It works for me and hope that my steps also help you.

它对我有用,希望我的步骤也能帮助到你。