有问题从ant中的属性文件中迭代值?(Problem iterating values from a property file in ant?)

编程入门 行业动态 更新时间:2024-10-26 00:26:25
有问题从ant中的属性文件中迭代值?(Problem iterating values from a property file in ant?)

我在尝试迭代属性文件中定义的值时遇到问题。 我正在尝试在循环中读取jar文件并将它们复制到目录中。 jar文件名在属性文件中定义。 这是我的示例文件:

<?xml version="1.0"?><project name="beehive" basedir="."> <taskdef resource="net/sf/antcontrib/antlib.xml"/> <loadfile property="file.list" srcFile="test.txt"> <!--<filterchain> <striplinebreaks/> </filterchain>--> </loadfile> <target name="testtarget"> <for list="${file.list}" param="fileName"> <sequential> <echo>@{fileName}</echo> <copy file="C:/Development/Doc/Build/@{fileName}" todir="C:/Development/Doc/Build/testdir"> </copy> </sequential> </for> </target>

这是test.txt中的条目。

wikihelp-1.0.0.jar

速度 - 1.0.0.jar

我期待for循环一次读取一个文件名,然后执行复制。 相反,它一起读取2个文件名并抛出以下异常:

警告:无法找到要复制的文件C:\ Development \ Doc \ Build \ wikihelp-1.0.0.jar velocity-1.0.0.jar。

任何指针将不胜感激。

谢谢

I'm having issues in trying to iterate values defined in a property file. I'm trying to read jar files in a loop and copy them to a directory. The jar file names are defined in a property file. Here's my sample file :

<?xml version="1.0"?><project name="beehive" basedir="."> <taskdef resource="net/sf/antcontrib/antlib.xml"/> <loadfile property="file.list" srcFile="test.txt"> <!--<filterchain> <striplinebreaks/> </filterchain>--> </loadfile> <target name="testtarget"> <for list="${file.list}" param="fileName"> <sequential> <echo>@{fileName}</echo> <copy file="C:/Development/Doc/Build/@{fileName}" todir="C:/Development/Doc/Build/testdir"> </copy> </sequential> </for> </target>

Here's the entry in test.txt.

wikihelp-1.0.0.jar

velocity-1.0.0.jar

I'm expecting that the for loop will read file name one at a time then perform the copy. Instead,its reading the 2 file names together and throwing the following exception :

Warning: Could not find file C:\Development\Doc\Build\wikihelp-1.0.0.jar velocity-1.0.0.jar to copy.

Any pointers will be appreciated.

Thanks

最满意答案

发现问题,添加delimiter =“$ {line.separator }解决了它

在for循环中,我需要为行分隔符添加分隔符

<for list="${file.list}" param="fileName" delimiter="${line.separator}">

Found the issue, adding delimiter="${line.separator} resolved it

In the for loop, I needed to add the delimeter for line seperator

<for list="${file.list}" param="fileName" delimiter="${line.separator}">

更多推荐

file,jar,文件,电脑培训,计算机培训,IT培训"/> <meta name="description"

本文发布于:2023-08-06 17:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454250.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   迭代   文件   ant   Problem

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!