如何在 Eclipse 的类路径上放置文件?

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

How to place a file on classpath in Eclipse?

eclipseclasspath

提问by Cacheing

As this documentationsays, "For example if you place this jndi.properties file on your classpath", but how can I place the .properties file on my classpath if I am using Eclipse?

正如本文档所说,“例如,如果您将此 jndi.properties 文件放在您的类路径上”,但是如果我使用 Eclipse,我如何将 .properties 文件放在我的类路径上?

采纳答案by paulsm4

One option is to place your properties file in the src/ directory of your project. This will copy it to the "classes" (along with your .class files) at build time. I often do this for web projects.

一种选择是将您的属性文件放在项目的 src/ 目录中。这将在构建时将其复制到“类”(以及您的 .class 文件)。我经常为 Web 项目执行此操作。

回答by greenkode

Just to add. If you right-click on an eclipse project and select Properties, select the Java Build Pathlink on the left. Then select the SourceTab. You'll see a list of all the java source folders. You can even add your own. By defaultthe {project}/srcfolder is the classpath folder.

只是为了补充。如果右键单击 Eclipse 项目并选择Properties,请选择Java Build Path左侧的链接。然后选择Source选项卡。您将看到所有 java 源文件夹的列表。您甚至可以添加自己的。通过默认{project}/src文件夹是文件夹的类路径。

回答by Ilia Koulikov

This might not be the most useful answer, more of an addendum, but the above answer (from greenkode) confused me for all of 10 seconds.

这可能不是最有用的答案,更像是一个附录,但上面的答案(来自 greenkode)让我困惑了整整 10 秒。

"Add Folder" only lets you see folders that are the sub-folders of the project whose build path you are looking at.

“添加文件夹”仅允许您查看作为您正在查看其构建路径的项目的子文件夹的文件夹。

The "Link Source" button in the above image would be called "Add External Folder" in an ideal world.

理想情况下,上图中的“链接源”按钮将被称为“添加外部文件夹”。

I had to make a properties file that is to be shared between multiple projects, and by keeping the properties file in an external folder, I am able to have only one, instead of having a copy in each project.

我必须制作一个在多个项目之间共享的属性文件,并且通过将属性文件保存在外部文件夹中,我可以只有一个,而不是在每个项目中都有一个副本。

回答by anzala

Well one of the option is to goto your workspace, your project folder, then bin copy and paste the log4j properites file. it would be better to paste the file also in source folder.

选项之一是转到您的工作区、您的项目文件夹,然后将 log4j 属性文件 bin 复制并粘贴。最好将文件也粘贴到源文件夹中。

Now you may want to know from where to get this file, download smslib, then extract it, then smslib->misc->log4j sample configuration -> log4j here you go.

现在你可能想知道从哪里得到这个文件,下载 smslib,然后解压它,然后 smslib->misc->log4j 示例配置 -> log4j 在这里你去。

This what helped,me so just wanted to know.

这有什么帮助,我只是想知道。

回答by Batwoman05

Copy the file into your src folder. Go to the Project Explorer in Eclipse, Right-click on your project, and click on "Refresh". The file should appear on the Project Explorer pane as well.

将文件复制到 src 文件夹中。转到 Eclipse 中的项目资源管理器,右键单击您的项目,然后单击“刷新”。该文件也应出现在“项目资源管理器”窗格中。