【问题标题】:Config and Run Ant from shell script从 shell 脚本配置和运行 Ant
【发布时间】:2015-03-06 10:34:08
【问题描述】:

我想从终端使用 Ant(1.8) 构建我的项目(我使用 ubuntu),并且想知道我的 shell 脚本何时运行。
1. 如何设置 Ant_Home ?没有在 bashrc 或任何其他位置设置路径,我的脚本需要设置用于构建项目的 Ant。 (这是因为,有些项目是用 Ant 1.7 运行的。)

  1. 如何在我的脚本中按顺序运行几个 build.xml 文件(如果之前运行的构建文件成功,则依次运行)。此外,让我知道如何将参数从终端传递到 shell 脚本,以便可以更改 Ant 主页。

  2. 我的 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 构建文件的路径。

标签: java linux shell ant


【解决方案1】:

请注意,这也是伪代码,有点……

export ANT_HOME=/path/to/ant #this will export the path variable for this session

或者如果您想将其作为输入读取

read ANT_HOME; export ANT_HOME
read buildXml1; read buildXml2
echo "Building"
ant build -buildfile $buildXml1  #You now have ant command available

antReturnCode=$?

echo "ANT: Return code is: \""$antReturnCode"\""

if [ $antReturnCode -ne 0 ];then

    echo "BUILD FAILED"
    exit 1;
else

    echo "BUILD SUCCESSFUL"
fi

等等与验证...

如果可以的话,我也给你一些建议。如果您打算构建这样的脚本以供使用,您必须先通过一些教程来完善您的游戏。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 2013-07-29
    相关资源
    最近更新 更多