In the Ant documentation on the jar command, it says that the destfile attribute is required.
However there is an example at the bottom that uses the jarfile attribute and does not use the destfile attribute. Also, I have functioning code from a work colleague that uses the jarfile attribute in a build.xml file for a Netbeans project.
So it would seem that destfile is not required, or can be replaced by jarfile.
Are jarfile and destfile identical?
Are there cases where you should use one and cases where you should use the other?
Thanks in advance
Yes, jarfile is a deprecated alias for destfile.
The implementation of jar is a subclass of the implementation of zip - as is ear and war. Each of them has a special (zip|jar|war|ear)file attribute. With Ant 1.5 we decided to unify this to destfile and deprecate the task-specific attributes.
Obviously we forgot to update all references inside the manual :-)
Related
I am trying to copy a file inside my ANT build script. For example the below copy statement -
<copy file="myfile.txt" tofile="mycopy.txt"/>
My doubt is- if by mistake/chance the physical file name becomes myFile.txt or MyFile.txt or MYFILE.txt, will the above statement still work??
I am unable to find any relevant documentation for the same. Please clarify if you are aware. Thanks.
UPDATE- I am aware that if I use fileset, I will be able to use 'casesensitive' attribute of fileset. But, I'm just using the 'file' type.
At the bottom of the copy page, it mentions if a file with a different case exists in windows, it copies over it. This to me indicates it's OS dependent, hence linux would be case sensitive and Windows not so much.
https://ant.apache.org/manual/Tasks/copy.html
As you've already said, fileset allows you to control case-sensitivity.
When using the file attribute the task's copySingleFile method kicks in which uses File#exists to determine whether there is anything to copy. exists is case-sensitive on Unix-like systems and insensitive on Windows. So using the file attribute is platform dependent.
Given your doubt you probably want to use something like
<copy tofile="mycopy.txt">
<fileset file="myfile.txt" casesensitive="false"/>
</copy>
I have a build file, which has the following property in it.
<property name="schema.dir" value="src/main/resources/schema" />
This schema.dir is used to refer a wsdl file.The parent folder which contains the build.xml has a space in it like this folder name .
When I echoed the property it displayed only src/main/resources/schema.
But I can see from the ant logs that issue is with the space in the folder name.
Since the parent folder is having a space in it, I am not able to refer the wsdl.
Can somebody suggest a solution so that file can be accessed with out changing the folder name
Is it possible to provide directly full path to wsdl file?
Try to replace " " sign with "%20".
For test you can hardcode that and with ANT you can use the propertyregex task from Ant Contrib.
See Replacing characters in Ant property
Have you tried specifying your property as a location rather than a string so Ant knows it's dealing with a file path, you can also specify the path as relative to your base directory.
<property name="schema.dir" location="${basedir}/src/main/resources/schema"/>
Adding ${basedir} to the path may not be necessary after changing the property from a value to a location.
I have an ant build which contains tasks of format
build
build.foo.bar
So to add dependencies in gradle the first one is easy
build.dependsOn(...)
But the second one is interpreted as method nesting. I suspect there's a standard groovy way to do this but I haven't cracked it.
How do I reference an ant task containing periods in an build.gradle file?
project.tasks['build.foo.bar'].dependsOn(...)
should do the trick.
See Project.tasks, which returns a TaskContainer (extending TaskCollection), and TaskCollection.getAt() which, as its doc says, can be called using the [] operator.
I have problems connecting to CVS using ant build.xml.
I figured out the reason was whitespaces in package attribute of CVS task as:
<cvs cvsRoot=":pserver:user#xx.xxx.xxx.xx:/CVSREPO_CCP_MIG" dest="${basedir}" package="My Test Project"/>
I learned from the ant website( http://ant.apache.org/manual/Tasks/cvs.html ) that we may Use a nested <module> element if you want to specify a module with spaces in its name. This specifies a package/module to work on, unlike the package attribute, modules specified using this attribute can contain spaces in their name.
I tried using the following:
<cvs cvsRoot=":pserver:user#xx.xxx.xxx.xx:/CVSREPO_CCP_MIG" dest="${basedir}">
<module name="My Test Project"/>
</cvs>
This again complains:
build.xml:39: cvs doesn't support the nested "module" element.
How can I use the module element with the CVS tag?
The Ant version is 1.7.x.
As suggested by the comments above, the nested "module" element is available for Ant ver 1.8 +.
However, if you are on one of the earlier versions, you may specify your package/module name under package attribute of CVS task by adding '"' on the either end of the attribute value.
e.g. We can replace package="My Test Project" with package=""My Test Project"" in here.
I Have a property file which contains list of jars from different paths like this
/gwt/X/2.1.0/gwt-servlet.jar
/gwt/X/2.1.0/gwt-user.jar
/gwt/X/2.1.0/gwt-dev.jar
/gwt/X/2.1.0/gwt-soyc-vis.jar
/log4j/X/1.2.15/log4j-1.2.15.jar
/GWT_LOG/X/3.0.3/gwt-log-3.0.3.jar
/GWT_MATH/X/2.1/gwt-math-2.1.jar
/GWT_MATH/X/2.1/gwt-math-server-2.1.jar
/GWT_Commons_Logging/X/0.3/GWT-commons-logging/gwt-commons-logging-0.3.jar
/GWT_Commons_Logging/X/0.3/GWT-commons-logging/gwt-commons-logging-service-0.3.jar
I have around 1000 jars like this in this list.
I would like to remove relative paths before jar name and out put jar names in a new file some thing like this
gwt-servlet.jar
gwt-user.jar
gwt-dev.jar
gwt-soyc-vis.jar
log4j-1.2.15.jar
gwt-log-3.0.3.jar
gwt-math-2.1.jar
gwt-math-server-2.1.jar
gwt-commons-logging-0.3.jar
gwt-commons-logging-service-0.3.jar
This is not a one time activity, so i would like to create a target or task in My build.xml for daily usage.
<replaceregexp file="file.txt" match="[^ ]*/" replace="" byline="true" flags="g"/>
Ant isn't well suited for tasks like this. It's probably much more simple to write a simple Ant Task in Java for that (or a small Java program; just create File objects and invoke getName() to get the last path element).
But if you have to: script and scriptdef are probably your friends (provided that your version of Ant is recent enough; the docs mention 1.6.3). You can call any Java method from these scripts. See the manual for examples.