ANT - how to use exclude, excludesfile with javac?

Looked at a few posts on stackoverflow, as well as other sources (online + ANT definition definitions guide), but none of them have helped so far. I cannot exclude a file from compilation.

I have only one file that I want to exclude from compilation, and the ANT documentation does not actually provide details. I am trying to exclude HTMLParser.java from compilation. Also tried using excludesfile too. But it still matches HTMLParser.java

I wrote a simple ANT to explore the various options below.

Can someone tell me what happened?

 <javac srcdir="${utilitiesSrc}" destdir="${dest}"> <excludesfile name="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan\utilities\HTMLParser.java" /> </javac> 

 <project name="CompileMasatosan" default="main" basedir="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan"> <property name="dest" location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes" /> <property name="utilitiesSrc" location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan\utilities" /> <javac srcdir="${utilitiesSrc}" destdir="${dest}"> <exclude name="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan\utilities\HTMLParser.java" /> </javac> </project> 

HTMLParser.java I believe it has no dependency, since I commented out all lines except the class declaration line.

HTMLParser.java

 package com.masatosan.utilities; public class HTMLParser { /* commenting out since Eclipse doesn't like some characters :( public static final String escapeHTML(String s){ StringBuffer sb = new StringBuffer(); int n = s.length(); for (int i = 0; i < n; i++) { char c = s.charAt(i); switch (c) { case '<': sb.append("&lt;"); break; case '>': sb.append("&gt;"); break; case '&': sb.append("&amp;"); break; case '"': sb.append("&quot;"); break; case 'à ': sb.append("&agrave;");break; case 'À': sb.append("&Agrave;");break; case 'â': sb.append("&acirc;");break; case 'Â': sb.append("&Acirc;");break; case 'ä': sb.append("&auml;");break; case 'Ä': sb.append("&Auml;");break; case 'Ã¥': sb.append("&aring;");break; case 'Ã…': sb.append("&Aring;");break; case 'æ': sb.append("&aelig;");break; case 'Æ': sb.append("&AElig;");break; case 'ç': sb.append("&ccedil;");break; case 'Ç': sb.append("&Ccedil;");break; case 'é': sb.append("&eacute;");break; case 'É': sb.append("&Eacute;");break; case 'è': sb.append("&egrave;");break; case 'È': sb.append("&Egrave;");break; case 'ê': sb.append("&ecirc;");break; case 'Ê': sb.append("&Ecirc;");break; case 'ë': sb.append("&euml;");break; case 'Ë': sb.append("&Euml;");break; case 'ï': sb.append("&iuml;");break; case 'à ': sb.append("&Iuml;");break; case 'ô': sb.append("&ocirc;");break; case 'Ã"': sb.append("&Ocirc;");break; case 'ö': sb.append("&ouml;");break; case 'Ö': sb.append("&Ouml;");break; case 'ø': sb.append("&oslash;");break; case 'Ø': sb.append("&Oslash;");break; case 'ß': sb.append("&szlig;");break; case 'ù': sb.append("&ugrave;");break; case 'Ù': sb.append("&Ugrave;");break; case 'û': sb.append("&ucirc;");break; case 'Û': sb.append("&Ucirc;");break; case 'ü': sb.append("&uuml;");break; case 'Ü': sb.append("&Uuml;");break; case '®': sb.append("&reg;");break; case '©': sb.append("&copy;");break; case '€': sb.append("&euro;"); break; // be carefull with this one (non-breaking whitee space) case ' ': sb.append("&nbsp;");break; default: sb.append(c); break; } } return sb.toString(); } */ }// 

UPDATE

As stated in the comment, I change the attribute name of excludefile to the relative path srcdir, and that’s it! So, the cut off looks like this:

 <javac srcdir="${utilitiesSrc}" destdir="${dest}"> <excludesfile name="HTMLParser.java" /> </javac> 
+4
source share
2 answers

I am sure that you have already verified that nothing you compile depends on HTMLParser. If so, the javac command will compile the file anyway.

To clarify, the problem above used an absolute path with the exclude property. When srcdir is specified, ant creates an implicit path with the names of the excluded files.

+5
source

Try specifying exclude as the path to the javac srcdir ( =${utilitiesSrc} ).

For example, your last javac task would be:

 <javac srcdir="${utilitiesSrc}" destdir="${dest}"> <exclude name="HTMLParser.java" /> </javac> 

If the file is buried somewhere in a subdirectory in the ${utilitiesSrc} directory, you can map it to wildcard :

 <javac srcdir="${utilitiesSrc}" destdir="${dest}"> <exclude name="**/HTMLParser.java" /> </javac> 
+8
source

All Articles