我想在构建过程中将一个文件复制到多个目录。
${prop.fmt}
中的值有两个目录,我只想将一个WAR文件复制到这两个目录中:
/apps/phxadmin-dev/devd/ui_tomcats/tomcat_c345tczuwdvd2/webapps
/apps/phxadmin-dev/devd/ui_tomcats/tomcat_c404gxduwdvd1/webapps
My Ant script:
<target name="test" >
<dirset id="dir.name" dir="${phx.tomcat.dir}" includes="*/webapps"/>
<property name="prop.dist.contents" refid="dir.name"/>
<loadresource property="prop.fmt">
<string value="${prop.dist.contents}"/>
<filterchain>
<tokenfilter>
<replaceregex pattern=";" replace="${line.separator}" flags="g"/>
</tokenfilter>
<prefixlines prefix="${phx.tomcat.dir}/" />
</filterchain>
</loadresource>
<echo message="${prop.fmt}"/>
<copy file="${phx.deploy.dir}/${war.file.name}" todir="${prop.fmt}"/>
</target>
请问有人能帮帮我吗?
<copy>
任务可以通过以下方式复制到多个目的地:
- 设置
enableMultipleMappings
属性为true
- 和使用
<scriptmapper>
在您的示例中,整个<target name="test">
块可以替换为…
<target name="test">
<dirset id="dir.name" dir="${phx.tomcat.dir}" includes="*/webapps"/>
<copy todir="${phx.tomcat.dir}" enableMultipleMappings="true" verbose="true">
<fileset file="${phx.deploy.dir}/${war.file.name}"/>
<scriptmapper language="javascript">
<![CDATA[
var dirSet = project.getReference( "dir.name" );
var ds = dirSet.getDirectoryScanner( project );
var includes = ds.getIncludedDirectories( );
for ( var i = 0; i < includes.length; i++ )
{
self.addMappedName( includes[i] + "/" + source );
}
]]>
</scriptmapper>
</copy>
</target>
运行上面的脚本会得到如下输出:
test:
[copy] Copying 1 file to /apps/phxadmin-dev/devd/ui_tomcats
[copy] Copying my.war to /apps/phxadmin-dev/devd/ui_tomcats/tomcat_c345tczuwdvd2/webapps/my.war
[copy] Copying my.war to /apps/phxadmin-dev/devd/ui_tomcats/tomcat_c404gxduwdvd1/webapps/my.war