Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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
在复制任务期间更新xml文件_Xml_Groovy_Gradle - Fatal编程技术网

在复制任务期间更新xml文件

在复制任务期间更新xml文件,xml,groovy,gradle,Xml,Groovy,Gradle,在执行复制类型任务期间,更新zip存档中特定xml文件的最佳方法是什么 到目前为止,我所拥有的: def unzip() { copy { def zipFile = configurations.tomcat.singleFile from zipTree(zipFile) into 'dir' eachFile { fileCopyDetails -> file = fileCopy

在执行复制类型任务期间,更新zip存档中特定xml文件的最佳方法是什么

到目前为止,我所拥有的:

def unzip() {

    copy {
        def zipFile = configurations.tomcat.singleFile

        from zipTree(zipFile)
        into 'dir'

        eachFile { fileCopyDetails ->

            file = fileCopyDetails.file

            if ( file.getAbsolutePath().endsWith('conf' + File.separator + 'context.xml') ) {
                def contextXml = new XmlSlurper().parse(file)
                String contextStr = groovy.xml.XmlUtil.serialize(contextXml)

                println 'xml before:\n' + contextStr

                contextXml.appendNode { 
                    a('value')
                }

                contextStr = groovy.xml.XmlUtil.serialize(contextXml)
                println 'xml after:\n' + contextStr

                file.withWriter { outWriter ->
                    XmlUtil.serialize( new StreamingMarkupBuilder().bind{ mkp.yield contextXml }, outWriter )
                }
            }
        }
    }
}
这段代码的问题是,它只更新“tmp”文件夹中的xml文件,而不更新最终“dir”文件夹中的xml文件

提前感谢,,
PM

解决方案取决于您要更新的内容。你能发布“更新”吗?Hi@BenjaminMuschko,比如说一个ApacheTomcat服务器zip,我们将其解压为“dir”。在解压过程中,我们希望将conf/server.xml的Http端口从“8080”更新为“8090”。我已经尝试使用每个文件{…}来执行此操作,但是更新的xml只显示在“tmp”文件夹中,而不显示在最终的“dir”文件夹中。干杯,下午。