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

8

65

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

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.

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.

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.

The problem is, Eclipse tries to compile everything under src/main/resources/blazeds when 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.

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

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.

I've followed the SO answer here but 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/resources as a source directory (in preferences > Java Build Path > Source Tab) I've added exclusions for blazeds under the resource directory. I've tried every permutation of blazeds and ** as in *blazeds*, **/blazeds/**, etc.

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.


Update #2:

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

Red X's won't go away

Consumer answered 17/9, 2010 at 14:28 Comment(1)
Build Path > Exclude seems to be a good solution. It works perfectly in Eclipse Juno to modify Java Build Path.Atrocious
C
31

You can use the Configure Contents... on the menu of Problems panel. 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.

Chlamys answered 17/9, 2010 at 14:36 Comment(2)
Thanks for your response! This works better than what we were doing before but it suffers two problems. Most importantly, it's not a change that checks into version control. So I have to walk around to my other co-workers and have them do this. Second, it still tries to compile the classes. So on the left-hand side, I still see red X's on my top level project folders above the src/main/resource/blazeds directory. Other than those issues, this is fantastic! The problems no longer show up in problem view!! I didn't know anything about this feature of Eclipse.Consumer
7 years later, still can't figure how to get the red x suppressed :/Ravin
C
63

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 > }
Cleaner answered 15/12, 2012 at 19:13 Comment(5)
Sigh... I have a similar problem. My project has (virtual) folders with sources i.e. the sources are located elsewhere. I need to exclude some of these folders from the build. I used the above resource filter and I also set "exclude from build" for the same folder. The folder now appears dimmed but all sources from it are still being built.Pilaf
It works now. The problem was that the project was setup as C project while some of the linked sources were C++. After switching project to C++, enabling and disabling linked folders seems to work fine.Pilaf
Does not help in my case - this prevents the folder from being included in the build.Sunbonnet
sometimes for unknow reason it doesn't work from project. But it works from the parent folder, so right click on parent folders -> properties -> resources -> etc.Deliver
This also hides the folder. I want the folder with the awful legacy code to be there, just not warn me of all the errors.Ravin
C
31

You can use the Configure Contents... on the menu of Problems panel. 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.

Chlamys answered 17/9, 2010 at 14:36 Comment(2)
Thanks for your response! This works better than what we were doing before but it suffers two problems. Most importantly, it's not a change that checks into version control. So I have to walk around to my other co-workers and have them do this. Second, it still tries to compile the classes. So on the left-hand side, I still see red X's on my top level project folders above the src/main/resource/blazeds directory. Other than those issues, this is fantastic! The problems no longer show up in problem view!! I didn't know anything about this feature of Eclipse.Consumer
7 years later, still can't figure how to get the red x suppressed :/Ravin
D
8

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.

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.

Dally answered 28/10, 2011 at 14:24 Comment(1)
Seems to me that you can only exclude source folders from errors/warnings. What seems to be to be most missing/useful would be to be able to ignore warnings in target folders, as they contain generated code where you can't fix the warnings anyway (I've got several such warnings in some projects at the moment).Nocuous
C
3

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

Celt answered 20/9, 2010 at 13:50 Comment(3)
Unfortunately, that didn't work. But thanks for your response! I was excited to try it out. However "Exclude" isn't an option here under src/main/resources. I've updated my question with a picture. Exclude is an option under my source folders. I don't understand why this stupid thing is trying to compile!!Consumer
There is no Exclude because you have excluded it :). Can you try to copy one error you get from the folder here? And can I get clearer view of what behind that popup menu?Celt
exactly, there's no excuse! I'm starting to wonder if this is a bug because it wasn't a problem last year. All the errors are legitimate errors related to missing jars, etc. as in Feed cannot be resolved to a type. Silly Eclipse: since this source code isn't used, of course the jars aren't around! I can clear the errors by adding all kinds of lib folder and source folder references to my project settings but that's not the desired solution. It confuses others and overly complicates the project settings :(Consumer
M
0

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.

Assuming Eclipse Helios, step by step:

  • 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).

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).

Mcneese answered 23/9, 2010 at 23:14 Comment(3)
thanks for your suggestion. It does not use the standard java builder, unfortunately. This is a Maven project and for some odd reason it's attempting to build items that are not source folders.Consumer
A lot of the configuration options are for the java builder only. So you need to look into the Maven configuration settings. Probably this stuff here:Mcneese
maven.apache.org/plugins/maven-eclipse-plugin/examples/…Mcneese
S
0

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

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 .

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.

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

Seductive answered 12/8, 2016 at 9:44 Comment(0)
V
-1

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).

Vanillin answered 22/9, 2010 at 9:24 Comment(4)
Thanks for your suggestion, as I stated: 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. For reasons beyond my control, I can't enact your solution but I like the idea of using other projects for those kinds of purposes.Consumer
You can use my answer to support your argument to change this aspect of the project (like "an external export suggested this as the best solution").Vanillin
That does it. I'm storming in on Monday's meeting and demanding, "If it's good for Digulla, it's good enough for us!" :)Consumer
Well, that's how consultants work: They tell you what everyone already knows but since it's from "outside", no one looses face when they agree to something that they had been blocking before.Vanillin
A
-2

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

Addition answered 22/8, 2013 at 16:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.