为什么ant build使用sudo失败,即使以root用户身份运行也能成功?

时间:2013-01-21 04:31:55

标签: linux apache ant java redhat

我正在使用java build tool ant在服务器上编译Android应用程序。

当我以root用户身份运行以下内容时,构建成功:

export ANT_HOME=/usr/local/ant
export JAVA_HOME=/usr/local/jdk
export PATH=${PATH}:${ANT_HOME}/bin
cd /path/to/android/file
/usr/local/ant/bin/ant release

但是,当我以netuser(或我测试的任何其他用户)运行以下内容时:

export ANT_HOME=/usr/local/ant
export JAVA_HOME=/usr/local/jdk
export PATH=${PATH}:${ANT_HOME}/bin
cd /path/to/android/file
sudo /usr/local/ant/bin/ant release

我收到以下错误:

BUILD FAILED
/path/to/android/file/build.xml:83: The following error occurred while executing this line:
/usr/share/android-sdk/tools/ant/build.xml:206: Class org.apache.tools.ant.taskdefs.condition.And doesn't support the nested "matches" element.

我已经尝试更改sudoers文件,甚至给netuser所有权限netuser ALL =(ALL)ALL但是我得到相同的结果......有人可以告诉我我做错了吗?

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

我怀疑您在以sudo身份运行时没有获取环境变量。该错误消息表明它使用的Ant版本的旧版本比您预期的要多。

要查看是否是这种情况,请尝试以下(导出后)并查看它是否符合您的预期:

sudo env

要保留环境变量,请修改sudoers文件或使用-E选项。