Is there any way to skip some Java files when compiling under Eclipse?
-
1You can comment the entire file, empty Java files are compilable. – Bhushan Jan 06 '12 at 17:04
-
2any specific reason ignore those Java files? – kosa Jan 06 '12 at 17:04
-
3I am refactoring some code I didn't write and there are classes which contains errors or if not are unused. It bothers me to see them on the class list so I want to put them aside without deleting them. – UmNyobe Jan 06 '12 at 17:12
-
3You shouldn't keep unused classes in your project. Rather delete them and let your version control system revert them if you find out that you need them again. – 0lukasz0 Jan 06 '12 at 17:23
5 Answers
Remove the class from the build path. You can do this for a single file or group of files by selecting them in the Project Explorer, then right click → Build Path → Exclude.

- 354,903
- 100
- 647
- 710
-
2In newer versions of Eclipse, the menu option is "Resource configurations" -> "Exclude from build..." – Yoav Feuerstein Jan 22 '16 at 10:39
You can always exclude the item from being built. Right click on the file and go to build-path. Then click exclude.

- 5,799
- 3
- 20
- 27
-
1Perfect. It appears at the bottom of the project and you can add it again. – UmNyobe Jan 06 '12 at 17:09
Delete (or move) them. It can't compile what isn't there ;)
Note: Other forms of removing the content you don't want compiled also work.

- 30,869
- 25
- 117
- 173
There's another way to do it. I discovered it by first using the Build Path -> Exclude option in other answers, as Eclipse said something about configuring filters.
Right click the project -> click Properties -> click Java Build Path -> click Source tab -> select ProjectName/src -> click Edit... (or double click Excluded) -> add an Exclusion pattern like com/blah/blah/blah/, potentially with wildcards.
It looks like the wildcards are your standard * and ?, but they also have **, which appears to be for wildcarding any number of folders, which must imply that * and ? are for only wildcarding a single file/folder name.

- 5,839
- 1
- 51
- 72