java ANT - 如何在 javac 中使用 exclude、excludesfile?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3808612/
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
ANT - how to use exclude, excludesfile with javac?
提问by Meow
Looked at several post on stackoverflow as well as other sources (online + ANT definition guide book) but none of them helped so far. I can't exclude the file from compiling.
查看了有关 stackoverflow 以及其他来源(在线 + ANT 定义指南)的几篇文章,但到目前为止,它们都没有帮助。我无法从编译中排除该文件。
I have just one file that wants to exclude from compiling and ANT documentation is not really telling the detail.
I'm trying to exclude HTMLParser.java
from compiling.
Also tried using excludesfile
too. But it still complies HTMLParser.java
我只有一个文件要从编译中排除,而 ANT 文档并没有真正说明细节。我试图HTMLParser.java
从编译中排除。也尝试过使用excludesfile
。但它仍然符合 HTMLParser.java
I wrote simple ANT to examine trying different variation below.
我编写了简单的 ANT 来检查下面尝试不同的变体。
Could anyone tell me what's wrong?
谁能告诉我出了什么问题?
<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>
The HTMLParser.java I believe has no dependency since I commented all lines out except class declaration line.
我认为 HTMLParser.java 没有依赖性,因为我注释掉了除类声明行之外的所有行。
HTMLParser.java
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("<"); break;
case '>': sb.append(">"); break;
case '&': sb.append("&"); break;
case '"': sb.append("""); break;
case '??': sb.append("à");break;
case '?': sb.append("À");break;
case '?¢': sb.append("â");break;
case '??': sb.append("Â");break;
case '?¤': sb.append("ä");break;
case '??': sb.append("Ä");break;
case '?¥': sb.append("å");break;
case '?…': sb.append("Å");break;
case '?|': sb.append("æ");break;
case '??': sb.append("Æ");break;
case '?§': sb.append("ç");break;
case '??': sb.append("Ç");break;
case '??': sb.append("é");break;
case '?‰': sb.append("É");break;
case '?¨': sb.append("è");break;
case '??': sb.append("È");break;
case '?a': sb.append("ê");break;
case '??': sb.append("Ê");break;
case '??': sb.append("ë");break;
case '??': sb.append("Ë");break;
case '?ˉ': sb.append("ï");break;
case '??': sb.append("Ï");break;
case '?′': sb.append("ô");break;
case '?”': sb.append("Ô");break;
case '??': sb.append("ö");break;
case '?–': sb.append("Ö");break;
case '??': sb.append("ø");break;
case '??': sb.append("Ø");break;
case '??': sb.append("ß");break;
case '?1': sb.append("ù");break;
case '??': sb.append("Ù");break;
case '??': sb.append("û");break;
case '??': sb.append("Û");break;
case '??': sb.append("ü");break;
case '??': sb.append("Ü");break;
case '??': sb.append("®");break;
case '??': sb.append("©");break;
case 'a??': sb.append("€"); break;
// be carefull with this one (non-breaking whitee space)
case ' ': sb.append(" ");break;
default: sb.append(c); break;
}
}
return sb.toString();
}
*/
}//
UPDATE
更新
As suggested in the comment, I change the excludesfile name attribute to relative path of srcdir and that was it! So the snipped looks like:
正如评论中所建议的,我将 excludesfile name 属性更改为 srcdir 的相对路径,就是这样!所以剪辑看起来像:
<javac srcdir="${utilitiesSrc}" destdir="${dest}">
<excludesfile name="HTMLParser.java" />
</javac>
回答by martin clayton
Try specifying the exclude
as a path relative to the javac srcdir
(=${utilitiesSrc}
) directory.
尝试将 指定exclude
为相对于javac srcdir
( =${utilitiesSrc}
) 目录的路径。
For example, your last javac task would then be:
例如,您的最后一个 javac 任务将是:
<javac srcdir="${utilitiesSrc}" destdir="${dest}">
<exclude name="HTMLParser.java" />
</javac>
If the file is buried somewhere in a sub directory under the ${utilitiesSrc}
directory, you can match it with a wildcard:
如果文件隐藏在目录下的${utilitiesSrc}
子目录中,您可以将其与通配符匹配:
<javac srcdir="${utilitiesSrc}" destdir="${dest}">
<exclude name="**/HTMLParser.java" />
</javac>
回答by Andrew Hubbs
Obvious thing I imagine you have already checked is that nothing that you are compiling has a dependency in HTMLParser. If this is the case, the javac command will compile the file anyways.
我想您已经检查过的显而易见的事情是,您正在编译的任何内容都没有依赖于 HTMLParser。如果是这种情况,javac 命令无论如何都会编译文件。
To clarify, the problem above was using an absolute path with the exclude property. When a srcdir is given, ant creates an implicit path with exclude file names.
澄清一下,上面的问题是使用带有 exclude 属性的绝对路径。当给出 srcdir 时,ant 会创建一个带有排除文件名的隐式路径。