I have created Java FX bundle for Mac OS X using Ant. It creating bundle with two files -
1. MyApplication.app
2. MyApplication.dmg
I wish to copy both files at other folder, so I wrote command in my build.xml as -
<copy todir="my_new_folder">
<fileset dir="old_folder\bundles"/>
</copy>
It copying both files successfully at "my_new_folder". But on running .app from "my_new_folder" not launching my application though it is launching from "old_folder" correctly.
On comparing copied app I found that on exec (Unix Executable File) resided at MacOS folder ("Show Package Contents/Contents/MacOS") not preserving, its kind been changing in document file.
How to preserve its kind to Unix Executable File as I am simply executing simple copy directory.
Thanks,
Neelam Sharma
As noted in the ant copy task guide:
Unix Note: File permissions are not retained when files are copied; they end up with the default UMASK permissions instead. This is caused by the lack of any means to query or set file permissions in the current Java runtimes. If you need a permission-preserving copy function, use this instead:
<exec executable="cp" ... >
So, in your case, replace <copy> with:
<exec executable="cp">
<arg line="-R old_folder/bundles my_new_folder"/>
</exec>
(note that you should use forward slashes, even if this ant script is being used under Windows).
Related
I have a custom installer created through NSIS.
I have the following Ant task doing the same:
<target name="buildNSIS">
<exec executable="D:\NSIS\nsis-binary\makensis.exe" failonerror="true" >
<!-- providing some nsis definitions -->
<arg value="/DPROJECT_NAME=${ant.project.name}"/>
<!-- passing the script -->
<arg value=".\installer\MySetup.nsi"/>
</exec>
</target>
where MySetup.nsi is the script to run through NSIS for the installer.
I want to set an environment variable as part of the install process.
I read that its best to do using: https://nsis.sourceforge.io/EnVar_plug-in
However, the instruction there is confusing. It just says: Just extract the contents to your nsis directory (usually '$PROGRAMFILES\NSIS')
What does it mean?
My D:\NSIS\nsis-binary directory looks like:
So do I unzip Envar_plugin.zip inside Plugins directory above and start using EnVar::AddValue or EnVar::AddValueEx functions inside my MySetup.nsi as mentioned in Envar_plugin examples?
How do I use Envar_plugin so that my resultant custom installer through MySetup.nsi for my software will set environment variables during installation of my software?
Plug-ins have to be installed in the correct plug-in subdirectory inside the NSIS folder. Some plug-ins only have a .DLL file in the root of the .ZIP file and some already have the correct directory tree in the .ZIP. This specific plug-in has the latter and you can just extract the contents to your main NSIS folder.
If you try to execute a plug-in command (name::function) and NSIS cannot find the plug-in then you most likely put the .DLL file in the wrong folder. Recent versions of NSIS will print a list of directories it tried to search when this happens.
I have this ANT task to execute Sass in an eclipse project:
<project basedir="." default="sass">
<target name="sass">
<apply dest="www/styles" executable="sass">
<srcfile/>
<targetfile/>
<fileset dir="styles" includes="*.scss"/>
<mapper from="*.scss" to="*.css" type="glob"/>
</apply>
</target>
</project>
It works fine in Ubuntu. In Windows 7 I have to set the executable as sass.bat.
This is the error:
Buildfile: D:\my_workspace\my_project\build.xml
sass:
BUILD FAILED
D:\my_workspace\my_project\build.xml:3: Execute failed: java.io.IOException:
Cannot run program "sass" (in directory "D:\my_workspace\my_project"):
CreateProcess error=2, The system cannot find the file specified
Total time: 326 milliseconds
Both, sass and sass.bat can be invoked from the command line so as the Ruby/bin folder is in system PATH variable.
I don't want to mantain two versions of this file for different OS.
How can I solve this?
[not an answer-but too big for comment ]
Windows shell understand how to expand pathext. Ant does not interpret - it only try .exe, not others.
See comments for Windows Users
The task delegates to Runtime.exec which in turn apparently
calls ::CreateProcess. It is the latter Win32 function that defines
the exact semantics of the call. In particular, if you do not put a
file extension on the executable, only ".EXE" files are looked for,
not ".COM", ".CMD" or other file types listed in the environment
variable PATHEXT. That is only used by the shell.
Note that .bat files cannot in general by executed directly. One
normally needs to execute the command shell executable cmd using the
/c switch.
A common problem is not having the executable on the PATH. In case you get an error message
Cannot run program "...":CreateProcess error=2. The system cannot find
the path specified. have a look at your PATH variable. Just type the
command directly on the command line and if Windows finds it, Ant
should do it too. (Otherwise ask on the user mailinglist for help.) If
Windows can not execute the program add the directory of the program
to the PATH (set PATH=%PATH%;dirOfProgram) or specify the absolute
path in the executable attribute in your buildfile.
I've solved it by adding the conditional variable exec_file with value sass.bat for Windows family OS and sass for other.
<project basedir="." default="sass">
<condition property="exec_file" value="sass.bat" else="sass" >
<os family="windows" />
</condition>
<target name="sass">
<apply dest="www/styles" executable="${exec_file}">
<srcfile/>
<targetfile/>
<fileset dir="styles" includes="*.scss"/>
<mapper from="*.scss" to="*.css" type="glob"/>
</apply>
</target>
</project>
I'm looking for Ant task which will assemble Mac OS X PKG-file from my application files. Googled. No result. Any help?
I propose you get inspiration from this old mailing post and use Ant tasks copy, chmod, chown, tar, gzip instead of commands from shell... It still remains to call the /usr/bin/package command with exec. Maybe this little Perl script packagelint may help too.
So, i have found no special ant task. But i learned how to create Mac OS X package with PackageMaker from inside ant. First you have to create PackageMaker project manually. Create a package in PackageMaker then save it as, say, 'testpkg'. Now you need to add following code in your ant script.
<exec executable="/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker">
<arg value="--doc"/>
<arg value="./Installer/testpkg.pmdoc/"/>
<arg value="--out"/>
<arg value="${build.dir}/../test.pkg"/>
</exec>
Of cource you need to change some arguments to your paths.
This method is simple as if you create package manualy and then reassemble it automatically. But there is another side of medal: every time you have changes in files( e.g. new file must be included in package) you have to change your package project manualy.
There are another ways to create pkg( packager tool and variety of command line switches of PackageMaker itself). I choose easy way.
I write ant build script. I need to create a symlink and I found symlink task. According to manual, it works only on Unix. What happens if someone run my build script on windows platform? Will build fail? Or this task will be ignored on windows platform? Or in case of NTFS drive, it will even work?
I'm running Win7 and I tried it. Since I have Mingw installed it used ln. Ln seemed just to copy everything. Since a normal Windows installation does not have ln, it would fail there.
Here's what happens without ln:
C:\Users\Janus\Desktop>.\apache-ant-1.8.2\bin\ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
Buildfile: C:\Users\Janus\Desktop\build.xml
dist:
BUILD FAILED
C:\Users\Janus\Desktop\build.xml:3: Could not launch ln: java.io.IOException: Cannot run program "ln": CreateProcess error=2, The system can
not find the file specified
Total time: 1 second
C:\Users\Janus\Desktop>
Build.xml:
<project name="MyProject" default="dist" basedir=".">
<target name="dist">
<symlink link="lol" resource="d3dwindower" />
</target>
</project>
I created a condition property to identify if I am running on unix:
<condition property="isUnix">
<os family="unix"/>
</condition>
and then use an 'if' attribute on my target so it will only execute if on unix:
<target name="makeSymLinkToJar" depends="jar" if="isUnix">
<symlink link="${distlink.jar}" resource="${dist.jar}"/>
</target>
How do I get Apache Ant to delete a directory no matter what. I want it to be deleted even if there are locks or usages of the directory on windows.
I am using a continuous integration remote agent on a Windows box which fails to delete the build directory and as a result fails the build. This is extremely annoying and is disruptive to the statistics.
There is nothing actively using the directory, and the antivirus is disabled.
I just want to delete the directory no matter what. How can I achieve that on Windows with Apache Ant?
I think you will need external program to do this.
check this one:
_http://www.codeguru.com/cpp/w-p/files/fileio/article.php/c1287
here you have comparison of unlocking tools.Check this with command line interface:
_http://ccollomb.free.fr/unlocker/
If you know what process is holding your folder you can just call taskkill...(you can even kill explorer.exe but and you can start it again)
and if your folder is shared you can use net delete command
The best you can do in Ant is to set the parameters: quiet="true" and includeemptydirs="true" in order to prevent the build halting when the directory is missing or when a lock exists and to delete the top level directory even if it is empty. Eg:
<delete quiet="true" includeEmptyDirs="true">
<fileset dir="stubbornDir"/>
</delete>
You can also make sure that the resources you are attempting to delete are not read only, so include something like this in your script before your <delete> task:
<!-- The following only works on UNIX -->
<chmod perm="a+w">
<fileset dir="${dist.dir}">
<include name="**/*.jar"/>
<exclude name="${app.context.path}"/>
</fileset>
</chmod>
<!-- Win NT alternative -->
<echo message=" To permit file deletion, execute attrib.exe to change read permissions on: ${dist.dir}"/>
<exec dir="${dist.dir}" executable="attrib.exe" os="Windows NT,Windows 2000,Windows XP">
<arg line="-R **/*.jar"/>
</exec>
But, to answer your question, I'm afraid, using Ant, it is not possible to delete files or directories when a lock exists.
However, also be aware, if you have used the <javac> task earlier in your script, then unless you have set fork="true", the task will lock all files in your classpath and keep them locked during the entirety of your build.
Hope this helps!