您是否收到“不允许操作”错误消息?
例子
在 Ubuntu 上,chown 任务受操作系统限制:
$ ant
build:
[chown] chown: changing ownership of `/home/mark/tmp/build/one/test.txt': Operation not permitted
[chown] chown: changing ownership of `/home/mark/tmp/build/three/test.txt': Operation not permitted
[chown] chown: changing ownership of `/home/mark/tmp/build/two/test.txt': Operation not permitted
[chown] chown: changing ownership of `/home/mark/tmp/build': Operation not permitted
[chown] chown: changing ownership of `/home/mark/tmp/build/one': Operation not permitted
[chown] chown: changing ownership of `/home/mark/tmp/build/three': Operation not permitted
[chown] chown: changing ownership of `/home/mark/tmp/build/two': Operation not permitted
[chown] Result: 1
[chown] Applied chown to 3 files and 4 directories.
运行“chown”命令演示了相同的限制
$ chown -R an_other_user build
chown: changing ownership of `build/one/test.txt': Operation not permitted
chown: changing ownership of `build/one': Operation not permitted
chown: changing ownership of `build/two/test.txt': Operation not permitted
chown: changing ownership of `build/two': Operation not permitted
chown: changing ownership of `build': Operation not permitted
最好的解决方案是以 root 用户身份运行 ANT:
$ sudo ant
构建.xml
<project name="demo" default="build">
<target name="init">
<mkdir dir="build/one"/>
<mkdir dir="build/two"/>
<echo file="build/one/test.txt" message="helloworld"/>
<echo file="build/two/test.txt" message="helloworld"/>
</target>
<target name="build" depends="init">
<chown owner="an_other_user" verbose="true">
<fileset dir="build"/>
<dirset dir="build"/>
</chown>
</target>
<target name="clean">
<delete dir="build"/>
</target>
</project>