如何排除在 Eclipse 项目中产生警告/错误的文件夹?

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

How to exclude a folder that is producing warnings/errors in an Eclipse project?

eclipseidebuild-processm2eclipse

提问by gMale

Okay. I'm sick of this problem. This has tohave an easy fix, I'm sure of it!! I hope SO can help me to get rid of this once and for all!

好的。我厌倦了这个问题。这必须有一个简单的解决方法,我敢肯定!!我希望SO可以帮助我一劳永逸地摆脱这个!

Question

How do we get Eclipse to stop trying to process/compile all files under a particular project directory? The goal is for no errors/warnings to exist in the problems view if they relate to something in this folder or it's subfolders.

我们如何让 Eclipse 停止尝试处理/编译特定项目目录下的所有文件?目标是在问题视图中不存在与此文件夹或其子文件夹中的某些内容相关的错误/警告。

Background

背景

We run Eclipse 3.6 and the m2eclipse plugin v0.10.2.20100623 manages our autobuild. For reasons beyond my control, we have the entire BlazeDS distribution in our SVN project directory under src/main/resources/blazeds. Essentially, this directory contains a vanilla distribution of tomcat running blazeds to which all our configuration and project files are added when we deploy to our server via SCP.

我们运行 Eclipse 3.6,m2eclipse 插件 v0.10.2.20100623 管理我们的自动构建。由于我无法控制的原因,我们在src/main/resources/blazeds. 本质上,这个目录包含运行 blazeds 的 tomcat 的 vanilla 发行版,当我们通过 SCP 部署到我们的服务器时,我们所有的配置和项目文件都会添加到其中。

So, when we run deploy, this version of tomcat is copied to the server and our project is placed inside. Tomcat and our RIA application work and everything is fine.

所以,当我们运行deploy时,这个版本的tomcat被复制到服务器上,我们的项目就放在里面。Tomcat 和我们的 RIA 应用程序工作正常,一切正常。

The problem is, Eclipse tries to compile everything under src/main/resources/blazedswhen running AutoBuild and this generates about 300 errors/warnings in our problem view. So when a real error surfaces, it gets lost among the noise.

问题是,Eclipse 会src/main/resources/blazeds在运行 AutoBuild 时尝试编译所有内容,这会在我们的问题视图中生成大约 300 个错误/警告。因此,当真正的错误浮出水面时,它就会消失在噪音中。

The errors stem from code in /blazeds/tomcat/webapps/samples/testdrive-datapushand also the testdrive-httpservice, traderdesktopexample webapps. They have dependent source code that's not on the classpath and jars that aren't included in the libraries.

这些错误代码从遏制/blazeds/tomcat/webapps/samples/testdrive-datapush,也是testdrive-httpservicetraderdesktop例如webapps中。它们具有不在类路径中的依赖源代码和未包含在库中的 jar。

Failed Attempted Solutions

失败的尝试解决方案

I'm trying to push the proper solution: to remove the samples completely and also to get blazeds out of our version control. That's not happening anytime soon.

我正在尝试推出正确的解决方案:完全删除样本,并从我们的版本控制中移除 blazeds。这不会很快发生。

I've followed the SO answer herebut it's only a very temporary solution. I've tried adding exclusions everywhere I can think of and other members of my team have done the same. I've removed src/main/resourcesas a source directory (in preferences > Java Build Path > Source Tab) I've added exclusions for blazedsunder the resource directory. I've tried every permutation of blazedsand **as in *blazeds*, **/blazeds/**, etc.

我在这里遵循了SO 答案,但这只是一个非常临时的解决方案。我尝试在我能想到的所有地方添加排除项,我团队的其他成员也这样做了。我已删除src/main/resources作为源目录(在首选项 > Java 构建路径 > 源选项卡中)我blazeds在资源目录下添加了排除项。我试过的每一个排列blazeds,并**作为*blazeds***/blazeds/**等等。

I've even tried including the libraries and source files the compiler is complaining about but I couldn't get it right without excessively mangling our project configuration.

我什至尝试包括编译器抱怨的库和源文件,但如果不过度修改我们的项目配置,我就无法做到。

Summary

This has to be simple. What is the conventional way to exclude a folder that is producing warnings/errors in an eclipse project?


Update #1:
gedim's solution below is decent but it
1) doesn't clear red X's from the project
2) is a change everyone on our team needs to do, manually
(i.e., it's not in a project property file; thereby, it isn't checked into subversion)

I hope there's a way to address the core problem by telling Eclipse that this directory doesn't contain
items to compile/validate. Such a change would likely show up in one of the project setting files.

概括

这必须很简单。排除在 eclipse 项目中产生警告/错误的文件夹的常规方法是什么?


更新 #1:
下面的 gedim 解决方案不错,但它
1) 没有从项目中清除红色 X
2) 是我们团队中的每个人都需要手动进行的更改
(即,它不在项目属性文件中;因此,它未签入 subversion)

我希望有一种方法可以通过告诉 Eclipse 此目录不包含
要编译/验证的项目来解决核心问题。此类更改可能会出现在其中一个项目设置文件中。



Update #2:更新#2:

The picture below shows the red X's I'm trying to clear and that
Build Path > Exclude
isn't an option...

下图显示了我正在尝试清除的红色 X,这
Build Path > Exclude
不是一个选项......

Red X's won't go away

红色 X 不会消失

采纳答案by Giorgos Dimtsas

You can use the Configure Contents...on the menu of Problemspanel. There you can create a new configuration and set the scope to On Working Set:. Click on Select...and create a new working set that excludes the folders you don't want.

您可以使用面板Configure Contents...菜单上的Problems。您可以在那里创建新配置并将范围设置为On Working Set:. 单击Select...并创建一个新的工作集,排除您不想要的文件夹。

回答by TIER 0011

I encountered a similar problem and resolved it by moving the folder into my project folder. I then went to:

我遇到了类似的问题,并通过将文件夹移动到我的项目文件夹中来解决它。然后我去了:

  1. Project > Properties > Resource > Resource Filters > Add...
  2. Set Filter type = Exclude all.
  3. Set Applies to = Folders.
  4. Set File and Folder Attributes = { Name, matches, < your_folder_name > }
  1. 项目 > 属性 > 资源 > 资源过滤器 > 添加...
  2. 设置过滤器类型 = 全部排除
  3. 设置适用于 = 文件夹
  4. 设置文件和文件夹属性 = { 名称,匹配项,< your_folder_name > }

回答by Rhett Hudson

There is an Eclipse feature request for ignoring warnings from specified source folders.There have been several patches posted to the comment thread that provide implementations of the feature. It appears that a final patch is nearing the review stage for inclusion in an upcoming release.

有一个 Eclipse 功能请求用于忽略来自指定源文件夹的警告。已经在评论线程中发布了几个补丁,提供了该功能的实现。似乎最终补丁已接近阶段,以包含在即将发布的版本中。

Update 6/19/2012: Eclipse Juno 4.2M6 supports ignoring problems for a particular source folder. The feature is available on the Java Build Path dialog. See the release note.

2012 年 6 月 19 日更新:Eclipse Juno 4.2M6 支持忽略特定源文件夹的问题。该功能在 Java 构建路径对话框中可用。请参阅发行说明

回答by nanda

If you really want to exclude certain classes/packages from autobuild you can just right click on them and select Build Path -> Exclude

如果您真的想从自动构建中排除某些类/包,您可以右键单击它们并选择构建路径 -> 排除

alt text

替代文字

回答by soru

Configure your project (Project/Properties/Java Build Path/Source) to have, instead of the top level src folder with exclusions, just a list of the folders you do want to compile.

将您的项目(项目/属性/Java 构建路径/源)配置为具有您想要编译的文件夹列表,而不是具有排除项的顶级 src 文件夹。

Assuming Eclipse Helios, step by step:

假设Eclipse Helios,一步一步:

  • Turn off autobuild (Project/Build Automatically).
  • Start with it empty.
  • Delete the errors by right clicking as in the link (just to be sure).
  • Add genuine source folders 1 by 1 (Project/Properties/Java Build Path/Source/Add Folder)
  • Do an explicit build (Project/Build Project).
  • 关闭自动构建(自动项目/构建)。
  • 从空开始。
  • 通过右键单击链接删除错误(只是为了确定)。
  • 一一添加正版源文件夹(Project/Properties/Java Build Path/Source/Add Folder)
  • 进行显式构建(Project/Build Project)。

If that works, you should be able to turn autobuild back on. If it doesn't, something strange is going on. Perhaps the project is not using the standard Java Builder, but something like an Ant Builder (Project/Properties/Builders).

如果可行,您应该能够重新打开自动构建。如果没有,那么奇怪的事情正在发生。也许该项目使用的不是标准的 Java Builder,而是类似于 Ant Builder (Project/Properties/Builders) 的东西。

回答by Sowmya Rao

Go to Java Build Path -> Source -> Add Folder

转到 Java 构建路径 -> 源代码 -> 添加文件夹

Choose the right folders which needs to be part of Build Path

选择需要成为构建路径一部分的正确文件夹

In the above Screen shot src/main/resources needs to be removed from the build as it results in compilation error [wrong package ID]. Hence Include the Folder till src/main/resources .

在上面的屏幕截图中,需要从构建中删除 src/main/resources,因为它会导致编译错误 [错误的包 ID]。因此包括文件夹直到 src/main/resources 。

I did try Build Path -> Exclude. This does not actually solve the problem. i.e though the RedX mark is cleared from the Eclipse, it will no more be right Java projects. I.e user may not be able to run JUnit Test cases/ debug etc.

我确实尝试过构建路径-> 排除。这实际上并不能解决问题。即虽然 RedX 标记已从 Eclipse 中清除,但它不再是正确的 Java 项目。即用户可能无法运行 JUnit 测试用例/调试等。

But by including right folders, we can continue with as Java Project.

但是通过包含正确的文件夹,我们可以继续作为 Java 项目。

回答by Aaron Digulla

Since the files in the resource folder rarely change, I suggest to put them into a second project (where you can set different warning options) and then access that via a relative path (like ${basedir}/../special-tomcat).

由于资源文件夹中的文件很少更改,我建议将它们放入第二个项目(您可以在其中设置不同的警告选项),然后通过相对路径(如${basedir}/../special-tomcat)访问它。

回答by Javi

The best approach is to use the Inclusion and Exclusion Patterns option in the Java Build Path.
For example if you want to exclude one project of being automatically build:
1- Go to its Properties->Java Build Path->Source.
2- Expand the folder in the "Source folders on the build path:" area
3- Select Exclude->Edit
4- In the exclusion patterns add **
Note: for more information on this patterns: Include and Exclusion Patterns

最好的方法是使用 Java Build Path 中的 Inclusion and Exclusion Patterns 选项。
例如,如果要排除一个自动构建的项目:
1- 转到其属性->Java 构建路径->源。
2- 展开“构建路径上的源文件夹:”区域中的文件夹
3- 选择排除-> 编辑
4- 在排除模式中添加 **
注意:有关此模式的更多信息:包括和排除模式