gpt4 book ai didi

java - 从 shell 脚本配置和运行 Ant

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:53:26 26 4
gpt4 key购买 nike

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

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

  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=/path/to/ant #这将导出此 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

等等验证...

如果可以的话,也是一个和平的建议。如果您计划构建这样的脚本供使用,您必须在这样做之前使用一些教程来增强您的游戏。

关于java - 从 shell 脚本配置和运行 Ant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28896947/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com