【发布时间】:2015-03-06 10:34:08
【问题描述】:
我想从终端使用 Ant(1.8) 构建我的项目(我使用 ubuntu),并且想知道我的 shell 脚本何时运行。
1. 如何设置 Ant_Home ?没有在 bashrc 或任何其他位置设置路径,我的脚本需要设置用于构建项目的 Ant。 (这是因为,有些项目是用 Ant 1.7 运行的。)
如何在我的脚本中按顺序运行几个 build.xml 文件(如果之前运行的构建文件成功,则依次运行)。此外,让我知道如何将参数从终端传递到 shell 脚本,以便可以更改 Ant 主页。
我的 shell 脚本如何知道构建是否成功以便执行以后的命令。
编辑:我预期的 shell 脚本将是这样的。我对编写脚本和寻找类似下面的东西非常陌生。
ANT_HOME = {#exact ant home path here or value passed from terminal at run time}
ANT_BUILD_XML_FILE_1 #Define the build xml file. This values should be taken from the terminal inputs
ANT_BUILD_XML_FILE_2 #this values should be taken from the terminal inputs
set ANT_HOME #This line will load or call the ant home
ant build -buildfile ANT_BUILD_XML_FILE_1 # run the ant build file
if(#above build is successfull)
ant build -buildfile ANT_BUILD_XML_FILE_2 #run the 2nd build file.
if(#above build 2 is successful)
#some other command
echo"projects and jars built successfully"
【问题讨论】:
-
您可以使用简单的
export设置 ANT_HOME,并回答您后面的问题 - 是的,ant 会将任务/任务的退出代码返回给您可以使用的$?变量在您的脚本中进行验证。无论如何,您所想的一些代码 sn-ps 将帮助我们帮助您编写 shell 脚本。 -
@Dragan。非常感谢您的关注。我的问题已根据 shell 脚本的预期更新。
-
{#exact ant home path here or value passed from terminal at run time}这么说,您的意思是从 LUI 读取用户输入吗?就像在启动脚本时自己输入位置一样? -
@Dragan,是的,先生,作为用户输入读取。或者,对于 ant home,无需用户输入就足够了:直截了当,路径在脚本文件中设置,如 ANT_HOME = /myLibs//apache-ant-1.8.2 。设置路径可以作为用户输入或直接在文件中设置值。没关系。但最关心的是设置 ant 构建文件的路径。