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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 03:27:54  来源:igfitidea点击:

ANT - how to use exclude, excludesfile with javac?

javaantjavac

提问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.javafrom compiling. Also tried using excludesfiletoo. 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("&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 '?a': 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 '?1': 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 'a??': 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 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 excludeas 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 会创建一个带有排除文件名的隐式路径。