String ant:变量上的字符串操作
我有一个基于这个问题的问题 我想构建一个变量(我不能使用属性,因为我在一个循环中),它几乎是StringA-StringB。 (这可能是我对财产的误解,但只有在正确的情况下才能分配财产?) 我想我可以构建一个脚本函数来计算它,但我的猜测是,在一个已经存在的函数中必须能够实现它,这可能是我缺少的 这将是代码的一个示例String ant:变量上的字符串操作,string,variables,ant,String,Variables,Ant,我有一个基于这个问题的问题 我想构建一个变量(我不能使用属性,因为我在一个循环中),它几乎是StringA-StringB。 (这可能是我对财产的误解,但只有在正确的情况下才能分配财产?) 我想我可以构建一个脚本函数来计算它,但我的猜测是,在一个已经存在的函数中必须能够实现它,这可能是我缺少的 这将是代码的一个示例 <for param="file"> <path> <fileset dir="${mydir}" >
<for param="file">
<path>
<fileset dir="${mydir}" >
<include name="*.war"/>
</fileset>
</path>
<sequential>
<var name="undeploy_name" value="@{file} function_here ${mydir}" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="${undeploy_name}" />
</JBossCLI>
<deployToLiferay file="@{file}" />
</sequential>
</for>
总的来说,我想部署几场战争。当我运行它一次时,它工作得很好,但是如果我想让它重新运行,我需要首先取消部署它们
我只是这个接口的消费者,理想情况下deployToLiferay会自动取消部署,但它不会
谢谢你的反馈
编辑:如果我使用类似于链接页面上定义的内容,我会得到:
<loadresource property="file-to-deploy">
<propertyresource name="@{file}"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replacestring from="${mydir}" to=""/>
</tokenfilter>
</filterchain>
</loadresource>
10:52:49.541: * /data/contribution.xml:171: The following error occurred while executing this line:
10:52:49.541: * /data/contribution.xml:178: null doesn't exist
10:52:49.541://data/contribution.xml:171:执行此行时发生以下错误:
10:52:49.541://data/contribution.xml:178:null不存在
第178行是我的loadresource部分,ANT不是一种编程语言。我个人建议嵌入Groovy这样的脚本语言来处理一组文件:
<target name="process-files" depends="resolve">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="wars" dir="src/wars" includes="*.war"/>
<groovy>
project.references.wars.each {
ant.echo(message: "I want to do something with this ${it} file")
}
</groovy>
</target>
范例
process-files:
[echo] I want to do something with this /../src/wars/app1.war file
[echo] I want to do something with this /../src/wars/app2.war file
[echo] I want to do something with this /../src/wars/app3.war file
更新 下面的工作示例显示如何使用管理生成依赖项。这是一种存在于其他Java构建工具(如Maven)中的功能
<project name="demo" default="process-files" xmlns:ivy="antlib:org.apache.ivy.ant">
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<!--
==================
Normal ANT targets
==================
-->
<target name="process-files" depends="resolve">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="wars" dir="src/wars" includes="*.war"/>
<groovy>
project.references.wars.each {
ant.echo(message: "I want to do something with this ${it} file")
}
</groovy>
</target>
<!--
=============================
Dependency management targets
=============================
-->
<target name="resolve" depends="install-ivy">
<ivy:cachepath pathid="build.path">
<dependency org="org.codehaus.groovy" name="groovy-all" rev="2.4.7" conf="default"/>
</ivy:cachepath>
</target>
<target name="install-ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
</project>
project.references.wars.each{
echo(消息:“我想用这个${it}文件做点什么”)
}
感谢您的反馈,我知道ANT不是一种编程语言,但我想在没有太多外部工具的情况下编写流程脚本,我真的很想使用这些接口,因为它们是我使用的产品的“官方”API。如果需要的话,我不介意使用javascript之类的脚本语言,但现在我真的只想基于其他字符串构建一个字符串,这样我就可以随心所欲了like@MiguelCosta您已经有了外部工具,例如ant contrib,它不是标准ant(“for”任务)的一部分。您所采用的方法完全取决于您,我的建议是在需要编程时考虑使用Groovy或JavaScript。Groovy与ANT的集成非常好。Groovy实际上是Gradle的灵感来源,Gradle是一个更现代的java构建工具。最后,我扩展了我的答案,展示了如何使用ivy pluginI将构建依赖项作为一部分或您的ANT脚本进行管理。我知道我已经使用了一些外部工具,但这些工具是从我的项目继承而来的,groovy不是,除非我不得不这样做,否则我真的不想包含它。
<project name="demo" default="process-files" xmlns:ivy="antlib:org.apache.ivy.ant">
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<!--
==================
Normal ANT targets
==================
-->
<target name="process-files" depends="resolve">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="wars" dir="src/wars" includes="*.war"/>
<groovy>
project.references.wars.each {
ant.echo(message: "I want to do something with this ${it} file")
}
</groovy>
</target>
<!--
=============================
Dependency management targets
=============================
-->
<target name="resolve" depends="install-ivy">
<ivy:cachepath pathid="build.path">
<dependency org="org.codehaus.groovy" name="groovy-all" rev="2.4.7" conf="default"/>
</ivy:cachepath>
</target>
<target name="install-ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
</project>