Copy to restricted folder with Ant (using Eclipse in Ubuntu)
Using Eclipse in Ubuntu Linux.
I'm creating an ant task to delete a directory in my apache localhost directory (开发者_运维技巧/var/www) and then copy in files from my Eclipse project.
I have:
<project>
<target name="deploy">
<delete dir="/var/www/gds"/>
<copy todir="/var/www/gds/src">
<fileset dir="src">
</fileset>
</copy>
<copy todir="/var/www/gds/">
<fileset dir="web">
</fileset>
</copy>
</target>
</project>
However ant doesn't appear to have root user privileges to copy into this directory. It works if I open Eclipse using 'sudo Eclipse' but I don't really want to be running Eclipse in root.
Is there a way I can get ant to copy into this directory?
You could create an entry for the user you run Eclipse as in the /etc/sudoers file (using visudo or your sudo permissions editor of choice) to allow ant to run as root without a password. You would need to then get Eclipse to invoke "sudo ant" instead of just "ant" - I'm not familiar with Eclipse so maybe someone else can suggest if that's possible or not. Failing that you could wrap the ant binary in a shell script that invokes sudo ant, and then tell Eclipse that that is the ant binary instead.
This isn't an ANT issue it's an file-system permission problem in Ubuntu.
Everything under /var
is normally root access controlled. I agree that running your build as root is not the way to go :-)
I'd suggest creating a user directory under /var/www
and then read/write
your build files there.
For example:
sudo mkdir /var/www/gds
sudo chown myuser:myuser /var/www/gds
chmod 755 /var/www/gds
You still won't be allowed to delete the "gds" directory (because it's parent is owned by root) but you are allowed to delete everything inside it as follows
<delete>
<fileset dir="/var/www/gds" includes="**"/>
<delete>
精彩评论