如何防止 Eclipse 为每个构建清理 bin 文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6349519/
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
How to prevent Eclipse from cleaning the bin folder for every build?
提问by zw324
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.
我现在在用Eclipse做一个项目,我在bin文件夹中保存了一些资源文件(例如图像、文本),这些文件是程序需要的。
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?
但是,每次构建时,Eclipse 都会尝试清理文件夹,然后重新构建项目。清理时,它会删除文件夹中的资源文件。有没有办法阻止 Eclipse 这样做?
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.
我知道我可以更改文件的位置,但我也很好奇 Eclipse 为什么会这样做,以及是否可以防止这种情况发生。
Thanks!
谢谢!
采纳答案by Rodney Gitzel
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.
我不能确切地说出它为什么这样做,但可能这就是 Eclipse 进行构建的方式:清空“输出文件夹”并开始编译。
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.
也就是说,如果您将文件放入源文件夹中,那么 Eclipse 将bin
在每次构建时简单地将文件复制到,并且它们不会消失。它会做到这一点,以它不知道如何编译的任何文件,例如.xml
,.xsd
,.png
等
回答by usr-local-ΕΨΗΕΛΩΝ
Go to Options
-> Java
-> Compiler
-> Building
and uncheck Scrub output folders when cleaning projects
.
转到Options
-> Java
-> Compiler
->Building
并取消选中Scrub 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 in src
那对我有用。在我的项目中,我有一个 Ant 任务,它将一些配置资源添加到bin
文件夹中以将它们包含在类路径中,而无需将它们放入src
回答by Vanchinathan Chandrasekaran
You can consider using a maven style project and add the resources to the resources folder.
可以考虑使用maven风格的项目,将资源添加到resources文件夹中。
Here is a link to maven directory layout.
这是Maven 目录布局的链接。
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中使用什么样的项目。您可以在“项目”菜单中关闭自动构建功能。这将阻止 Eclipse 自动清理项目。
回答by Dave Carruthers
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.
将您的资源复制并粘贴到源文件夹中。在 Eclipse 中,在包资源管理器中,找到您的项目,然后粘贴到 src 中。然后它提供了一个选项来复制文件或链接到它。单击复制,它会存储在 /bin 中,但不会被删除。