目前需要使用ant来执行一个含有main方法的class文件,并且需要通过命令来行传两个参数(start和end)到main方法。
<target name="gsp" depends="compile" description="generator structure pictures">
<echo message="----------- Generator structure pictures ------------" />
<property name="start" value="1" />
<property name="end" value="892046" />
<java fork="true" classname="com.founder.cst.system.StructureImageGenerator">
<arg value="${start}"/>
<arg value="${end}"/>
<classpath path="${build.dir}/classes"/>
<classpath refid="classpath" />
</java>
<echo message="----------- End------------" />
</target>
这样执行ant gsp -Dstart=10 -Dend=20就可以把10和20传到main方法中了,最好设置默认值。
子曰:危邦不入,乱邦不居。天下有道则见,无道则隐。
<target name="gsp" depends="compile" description="generator structure pictures">
<echo message="----------- Generator structure pictures ------------" />
<property name="start" value="1" />
<property name="end" value="892046" />
<java fork="true" classname="com.founder.cst.system.StructureImageGenerator">
<arg value="${start}"/>
<arg value="${end}"/>
<classpath path="${build.dir}/classes"/>
<classpath refid="classpath" />
</java>
<echo message="----------- End------------" />
</target>
这样执行ant gsp -Dstart=10 -Dend=20就可以把10和20传到main方法中了,最好设置默认值。
子曰:危邦不入,乱邦不居。天下有道则见,无道则隐。
本文介绍如何使用Ant工具执行Java类文件并传递参数至main方法。通过配置<target>元素及<javafork>属性,实现从命令行传入参数start和end,同时提供了设置默认参数值的方法。
636

被折叠的 条评论
为什么被折叠?



