Tomcat 如果我知道使用ANT的文件夹名称不完整,如何将文件复制到该文件夹
下面是代码片段Tomcat 如果我知道使用ANT的文件夹名称不完整,如何将文件复制到该文件夹,tomcat,build,ant,terminal,Tomcat,Build,Ant,Terminal,下面是代码片段 <property name="apache.dst.dir" value="../../apache-tomcat-7.0.79/webapps" /> <copy todir="${apache.dst.dir}"> <fileset dir="${dstdir}"> <include name="api.war" /> </fileset> </copy> 我正在
<property name="apache.dst.dir" value="../../apache-tomcat-7.0.79/webapps" />
<copy todir="${apache.dst.dir}">
<fileset dir="${dstdir}">
<include name="api.war" />
</fileset>
</copy>
我正在尝试将war文件复制到ApacheTomcat下的webapps目录。但是,不同的用户可能有不同版本的tomcat,因此文件夹名称可能会有所不同。它将是ApacheTomcat之类的。我如何具体说明?我希望我的ant文件查找以apache tomcat-*/webapps开头的文件夹,并将该文件复制到该文件夹下的webapps中
我添加了*但是它创建了一个新文件夹,而不是查找具有类似名称的文件夹
感谢您的帮助 Ant的
属性
任务不能使用通配符,因此您必须使用资源集合来查找所需的目录。以下是我的建议:
<dirset id="tomcat.dir" dir="../.." includes="apache-tomcat-*" />
<fail message="Multiple Tomcat directories found in ${tomcat.parent.dir}.${line.separator}${toString:tomcat.dir}">
<condition>
<resourcecount refid="tomcat.dir" when="greater" count="1" />
</condition>
</fail>
<fail message="No Tomcat directory found in ${tomcat.parent.dir}.">
<condition>
<resourcecount refid="tomcat.dir" when="less" count="1" />
</condition>
</fail>
<pathconvert refid="tomcat.dir" property="tomcat.dir" />
<property name="tomcat.webapps.dir" location="${tomcat.dir}/webapps" />
<copy todir="${tomcat.webapps.dir}" file="${dstdir}/api.war" flatten="true" />
说明:
dirset
类型收集位于./..
中遵循“apachetomcat-*”模式的目录。这将存储为ID为“tomcat.dir”的Ant路径。(请随意将这些值重命名为“apache”或其他名称;这只是我的偏好,因为apache生产许多不同的产品。)
dirset
可能会收集多个目录,因此如果发生这种情况,您可能希望生成失败。否则,您将在脚本的后面出现一个令人困惑的错误dirset
类型本身不会使构建失败pathconvert
任务从tomcat.dir
路径创建属性。我给了他们相同的名字,但不一定是这样属性
任务专门为目标目录创建属性。注意使用位置
属性代替值
属性。这将导致属性值解析为具有适合用户操作系统的文件分隔符的规范路径(即,如果用户在Windows上,正向斜杠将转换为反向斜杠)flatte=“true”
属性,但如果不是这样,请继续删除该部分