从shell脚本配置和运行Ant

时间:2015-03-06 10:34:08

标签: java linux shell ant

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

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

  2. 我的shell脚本如何知道构建是否成功以便执行以后的命令。

  3. 编辑:我期望的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"
    

1 个答案:

答案 0 :(得分: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

等等验证......

如果可以的话,我也会给予和平的建议。如果你计划构建这样一个脚本以供使用,你必须先用一些教程来放大你的游戏。