如何防止 Eclipse 在每次构建时清理 bin 文件夹?
我现在正在使用Eclipse做一个项目,我在bin文件夹中保存了一些资源文件(例如图像,文本),这些文件是程序需要的。
然而,每次构建时,Eclipse 都会尝试清理文件夹,然后重建项目。清理时,会删除文件夹中的资源文件。有什么办法可以阻止 Eclipse 这样做吗?
我知道我可以更改文件的位置,但我也很好奇为什么 Eclipse 会这样做,以及是否可以防止这种情况发生。
谢谢!
I am now doing a project using Eclipse, and I have some resource files (e.g., image, text) saved in the bin folder, and these files are needed by the program.
However, with every build, Eclipse would try to clean up the folder, then rebuild the project. When cleaning, it deletes the resource files in the folder. Is there anyway to stop Eclipse from doing this?
I know I could change the location of the files, but I am also curious why Eclipse would do this, and could this be prevented from happening.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
转到
选项
->Java
->编译器
->构建
并取消选中清理项目时清理输出文件夹
。这对我来说很有效。在我的项目中,我有一个 Ant 任务,它将一些配置资源添加到
bin
文件夹中,以将它们包含在类路径中,而不将它们放在src
中Go to
Options
->Java
->Compiler
->Building
and uncheckScrub output folders when cleaning projects
.That did the trick for me. In my project, I have an Ant task that adds a few configuration resources to the
bin
folder to include them in the classpath, without having them insrc
我不能确切地说出它为什么这样做,但可能这就是 Eclipse 构建的方式:清空“输出文件夹”并开始编译。
也就是说,如果您将文件放入源文件夹中,那么 Eclipse 只会在每次构建时将文件复制到
bin
中,并且它们不会消失。它会对任何不知道如何编译的文件执行此操作,例如.xml
、.xsd
、.png
等。I can't say exactly why it does it, but probably that's just how Eclipse does the build: empty the "output folder" and start compiling.
That said, if you put your files into a source folder, then Eclipse will simply copy the files over to
bin
on every build and they won't disappear. It will do this to any file it doesn't know how to compile, e.g..xml
,.xsd
,.png
, etc.可以考虑使用maven风格的项目,并将资源添加到resources文件夹中。
这是 maven 目录布局的链接。
你在eclipse中使用什么样的项目。您可以在“项目”菜单中关闭自动构建功能。这将阻止 Eclipse 自动清理项目。
You can consider using a maven style project and add the resources to the resources folder.
Here is a link to maven directory layout.
What kind of project you are using in eclipse. You can turn off build automatically feature in the Project menu. Which would stop eclipse from cleaning up projects automatically.
将资源复制并粘贴到源文件夹中。在 Eclipse 中的包资源管理器中,找到您的项目,然后粘贴到 src 中。然后它提供了复制文件或链接到该文件的选项。单击复制,它会存储在 /bin 中,但不会被删除。
Copy and paste your resources into the source folder. In eclipse, in package explorer, find your project, then paste into src. It then gives an option to copy the file or link to it. Click copy and it gets stored in /bin but won't get deleted.