Is there a way to tell Eclipse to not include specified files, directories, or patterns in a JAR or WAR?
4 Answers
You can specify includes and excludes by opening the Project Properties (alt-enter) then opening Java Build Path and the Source tab. Against each source location there is a little plus sign, click on that then select Included or Excluded then select the Edit... button.
You can then specify multiple patterns for files to be included/excluded. These files will not be processed to the output directory. The patterns follow Ant's wildcard patterns so you have quite fine-grained control over what to include.
(source: eclipse.org)

- 21,988
- 13
- 81
- 109

- 83,208
- 23
- 172
- 177
-
Now that's cool, but that appears to only apply to files in the src directory. What actually brought this up was that I have files related to version control in the WebContent directory that I wanted to exclude. – Jay Sep 29 '09 at 13:26
-
It applies to any source location, if you specify that WebContent is a source location, it will work for that location too - though it might cause other problems – Rich Seller Sep 29 '09 at 14:34
-
This works to modify the build output but doesn't modify the _Exported WAR's contents_ as per OQ. To modify the WAR, cf. comment #4 in https://bugs.eclipse.org/bugs/show_bug.cgi?id=182534 (as referenced [from here](http://stackoverflow.com/questions/1294901/ignore-svn-files-when-exporting-a-war-file-from-eclipse?rq=1)). As a side-effect, this will also exclude the files from the project explorer. – user1944491 Jan 06 '15 at 20:09
-
@rich-seller, just wanted to let you know the first two links no longer work in case you wanted to correct them. Your ant link had a perfect example though! – JGlass Aug 09 '17 at 20:35
We fought with this problem too and didn't find a good standard solution for it in Eclipse WTP.
Hence we added Project Archives to JBoss Tools (http://jboss.org/tools) which allow you to control explicitly via "ant filter sets" what goes in and what goes out of your archive. This archive you can then deploy with the standard WTP mechanism for deployment on the server types supplied by JBoss tools.
We are working on adding similar support back into native Eclipse WTP, but that won't be available until sometime next year.

- 3,630
- 2
- 23
- 28
to add to what @Rich_Seller said: in Eclipse Indigo:
- Select your package from the package view right click, and choose Export.
- Choose Java -> JAR file from the "select an export destination" tree.
Click Next to go to the next page of the wizard.
Under the "Select the resource to export" you are presented with a tree view here you can select and deselect components that will be included and excluded from the JAR.

- 183
- 1
- 13
I think including an XML file in another and then removing its visibility in the war file should give you an on off switch.

- 9,870
- 11
- 54
- 102