I have an Ant script performing some updating etc and one task is to delete a few files and folders.
In Windows and especially version 7 there seem to be some kind of Read Only Attribute mayhem and I have tried several solutions with no success.
There are several other SO issues similar to this but no solution really.
Ant is not able to delete some files on windows
Is there any way to make Ant ignore the Read Only Attribute?
The ant chmod task seems only to work for Linux; searching for "ant chmod windows" yielded i.a. Attr. Then you could first make all writable. Maybe with ant delete failonerror=false.
Okay, that does not work too. Maybe use PsExec, a tool to run things as Administrator. Unlikely that a solution in the form of an ant task may be found.
Related
I added ant-contrib-1.0b3.jar into ANT lib folder. But when I executed ANT performance monitor task in Cygwin, it still reported CLASS NOT FOUND.
However, if I do same job in Windows command-line, the building is working fine.
Is there anyone knows what is going on?
BTW, I confirmed that WIN-CMD and Cygwin are using same ANT.
Thanks
Try this approach:
There isn't antlib.xml in my ant-contrib-0.3
Create a target that automatically installs ant-contrib if it's missing.
I'm running an ant build through Jenkins and on the stage where it is deploying to windows-share its returning the following error:
Failed to copy FILE to FILE2 due to failed to create the parent directory for FILE2 (I've taken the paths out to keep the question shorter).
I'm guessing that there might be some problem with permissions with the jenkins default user but this problem has only just started occurring, and any help would be great.
Thanks
This is a pretty old question but I thought I'd come back and complete it with a short update as to what was actually going on. Someone had changed the password for the user that was logged on to the vm that jenkins was running on, and when it was trying to create the directory to stick the files into it was running into permissions errors. Only problem was the error message wasn't very descriptive.
So in the end this was an infrastructure problem rather than anything to do with the ant script.
I take it you're doing something like this:
<copy file="${from.dir}/${from.file}"
tofile="${to.dir}/${to.file}"/>
And, you're getting an error that ${to.dir} doesn't exist.
In earlier versions of Ant, you definitely had to create the directory before doing a copy:
<mkdir dir="${to.dir}"/>
<copy file="${from.dir}/${from.file}"
tofile="${to.dir}/${to.file}"/>
I think I also noticed that later versions of Ant will create the directory for you when that directory didn't exist. I've always been in the habit of putting <mkdir/> in front of any task that creates a new file in a new directory, including things like <zip/> and <tar/>.
Here are some questions:
Do your users also use Ant to run their builds? I know that this isn't always the case. Many users use Eclipse and don't bother with Ant.
Is the version of Ant your users have vs. what your users have the same?
Do you do a clean? Jenkins can emulate a clean either by doing an update, reverting and removing unversioned element, or by simply creating a brand new working directory. If your users don't remove the destination directory where ${to.file} is being placed, it might work locally, but not on Jenkins.
Can you manually run Ant from the Jenkins working directory. If so, what results do you get? (Remember to disable this Jenkins job before doing this. You don't want Jenkins to do a build while you're experimenting in the working directory.)
My ant files are already present and I am not allowed to change those for various reasons. I have created a batch file and I am writing all those ant commands in that batch file just to automate the process. The code looks something like this
1. cd abc
2. ant realclean && ant
3. cd..
4. cd pqr
5. ant realclean && ant
6. cd..
However now I have to check if the build fired on line 2 is successful then only goto line 3 otherwise exit.
I googled a bit and found %errorlevel% as one option but it is not working in my case.
Any suggestions?
Thanks in advance.
How about adding another ANT file which contains the tasks to execute the existing ANT files?
That would give you error handling without doing anything, you could reuse that file on different OSs and your CI server and the syntax would be saner than batch...
You can have ANT execute, say project.xml, with ant -f project.xml
[EDIT] You don't even have to change the existing projects: Just create a new project, assign paths to the old projects to properties in the new build.xml and then you can build the old projects from the new one.
This gives you:
A sane[*] syntax that you already know (no need to learn the ugly/buggy/handicapped rules of DOS batch programming; you did know that DOS was once named QDOS "Quick and Dirty OS", yes?)
Proper error handling
A simple way to pass arguments to the sub-builds
Cross-platform support
Useful error messages when something goes wrong
[*]: Compared to DOS...
When i try to build to the parent folder with HTML5 Boilerplate build script i get this message:
Your dir.publish folder is set to ../ which could delete your entire site or worse.
Firstly, the build script doesn't delete any files, it just replaces them right?
Secondly, "or worse"? It's not like I'm googling google or mixing nitroglycerin here :(
Is there a work around?
EDIT:
I deleted this line in build.xml:
<equals arg1="${dir.publish}" arg2="../"/>
It works fine but i feel a bit dirty. Should i?
Haha, I wrote that error message, sorry :( but there is an ant task (clean) in build script which is to delete the publish and intermediate folders. And if you set your publish folder to ../ you can imagine what can happen :)
As stated in the edit. I funked around in the build.xml and deleted this line:
<equals arg1="${dir.publish}" arg2="../"/>
I haven't had any problems yet but use with caution.
I'm having problems building my project, using an Ant script, from the command prompt using Ant itself. It can't find a certain import for a particular Java file in my project (which has nearly 5,000 source files as it is). The import is included in a .jar package whose location I have set in the Ant file itself. (As a pathelement, along with other needed JARs that either are fine, or haven't tried to been used when the crash occurs). The crash happens with javac, with the simple message of "import etc.ect.* cannot be found at line etc" Oddly enough, I can build the project just fine from the Ant file using an IDE like Eclipse. Any ideas what could be wrong? Thanks!
Wow, the solution was completely unrelated. It was a dumb fault in the java code where the class was trying to import .* from a directory that only had folders in it. For some reason, Eclipse didn't seem to mind, but javac did!
Eclipse's root classloader contains a lot of classes, when you run ant from console there's much less.
Just tell javac task to use the required .jar, and you'll be fine.
You should post the stack trace, does it say "import required by ..."? ( I forget the exact text). Likely there's a jar that's available in your eclipse environment that is not included in your ant script. Look in the stack trace for the missing class to identify the jar that's not being included in your build.