Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ant XML自定义文件夹名称_Xml_Ant_Ant Contrib - Fatal编程技术网

Ant XML自定义文件夹名称

Ant XML自定义文件夹名称,xml,ant,ant-contrib,Xml,Ant,Ant Contrib,我不熟悉Ant和XML,我需要一些问题方面的帮助 我想创建一个根文件夹,其名称类似 [数字][时间戳][一些字符串]\u等 我将向您展示我的第一段代码,其中我只是从文件中读取值 <target name="create"> <loadfile srcfile="new.txt" property="fisier" /> <for param="line" list="${fisier}" delimiter="${line.separator}">

我不熟悉Ant和XML,我需要一些问题方面的帮助

我想创建一个根文件夹,其名称类似

[数字][时间戳][一些字符串]\u等

我将向您展示我的第一段代码,其中我只是从文件中读取值

<target name="create">

   <loadfile srcfile="new.txt" property="fisier" />
   <for param="line" list="${fisier}" delimiter="${line.separator}">
         <sequential>
            <echo>@{line}</echo>
            <propertyregex property="item"
              input="${line}"
              regexp="regexpToMatchSubstring"
              select="\1"
              casesensitive="false" />
         </sequential>
       </for>
   </target>

@{line}

从我读取的值中,我需要用regexp减去一个字符串。我有一些像id=2344的东西,我只需要数字,意思是等号右边的字符串。如何实现这一点?

使用通用编程语言实现这种需求要简单得多。您的示例演示了如何要求ant contrib库提供“for”ant任务

下面是一个替代实现,使用:

运行如下

build:
   [groovy] 2222
   [groovy] 2223
   [groovy] 2224
data.txt 编译文件

新文件(“data.txt”).eachLine{line->
def num=line=~/.*=(\d+)/
println num[0][1]
}
注:

  • 包括安装groovy任务所需的jar的附加目标。使构建更具可移植性

这个问题与ANT有什么关系?我只想编写build.xml并在命令行中运行它。这怎么可能与蚂蚁无关呢?谢谢你用一个例子来澄清你的问题。
├── build.xml
└── data.txt
build:
   [groovy] 2222
   [groovy] 2223
   [groovy] 2224
id=2222
id=2223
id=2224
<project name="demo" default="build">

  <available classname="org.codehaus.groovy.ant.Groovy" property="groovy.installed"/>

  <target name="install-groovy" unless="groovy.installed">
    <mkdir dir="${user.home}/.ant/lib"/>
    <get dest="${user.home}/.ant/lib/groovy.jar" src="http://search.maven.org/remotecontent?filepath=org/codehaus/groovy/groovy-all/2.3.6/groovy-all-2.3.6.jar"/>
    <fail message="Groovy installed run the build again"/>
  </target>

  <target name="build" depends="install-groovy">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
    <groovy>
    new File("data.txt").eachLine { line ->
      def num = line =~ /.*=(\d+)/
      println num[0][1]
    }
    </groovy>
  </target>

</project>