【问题标题】:Why is using a period to separate words the convention for target names in an Ant build file?为什么在 Ant 构建文件中使用句点分隔单词是目标名称的约定?
【发布时间】:2010-02-13 02:37:24
【问题描述】:

我一直不太明白这一点,因为 name 属性似乎支持空格,但每个示例都使用更难阅读的句点来命名目标。

为什么这样做:

<target name="some.target.name">
<!-- target child nodes -->
</target>

什么时候可以这样做:

<target name="Some Target Name">
<!-- target child nodes -->
</target>

这是有什么原因,还是技术限制?构建属性也是如此。他们总是使用点符号。

【问题讨论】:

    标签: java ant naming-conventions target


    【解决方案1】:

    一个原因可能是如果没有空格,在命令行上指定构建目标会更容易。使用空格,您必须在整个目标名称周围加上引号。

    【讨论】:

    • 我还使用它来将我的构建脚本分成不同的脚本,有一个主脚本 (build.xml) 和几个子脚本。规则是所有子脚本的目标都以文件名开头。例如,test.execute 是文件test.xml 中名为execute 的目标。我发现更容易管理和查找目标所在的位置。
    【解决方案2】:

    如果您的目标名称中有空格,则需要在命令行中将它们用引号括起来,否则处理器将像处理多个目标一样处理它们。

    试试这个: build.xml:

    <project name="MyProject" default="some target name" basedir=".">
      <target name="some target name">
        <echo>reached some target name with spaces</echo>
      </target>
      <target name="some">
        <echo>reached some</echo>
      </target>
      <target name="target">
        <echo>reached target </echo>
      </target>
      <target name="name">
        <echo>reached name</echo>
      </target>
    </project>
    

    用空格运行ant some target name,你会得到以下结果:

    Buildfile: build.xml
    
    some:
         [echo] reached some
    
    target:
         [echo] reached target 
    
    name:
         [echo] reached name
    
    BUILD SUCCESSFUL
    Total time: 0 seconds
    

    但使用引号,处理方式不同:ant "some target name"

    Buildfile: build.xml
    
    some target name:
         [echo] reached some target name with spaces
    

    【讨论】:

      猜你喜欢
      • 2011-03-11
      • 1970-01-01
      • 2013-11-02
      • 2023-03-24
      • 2021-01-09
      • 2015-08-12
      • 2010-09-19
      • 1970-01-01
      相关资源
      最近更新 更多