I am using Ant files for build
The build itself is done by IBM Rational Team Concert (RTC) with the help of this Ant file.
My problem is that if I make a mistake in the build XML itself like wrongly typed attribute name, this itself is detected by RTC after loading the files from source control (normally 15-20 mins)
Is there a way to verify (validate) the Ant XML file itself?
There is no schema for an Ant XML. As explained in the FAQ an incomplete DTD can be created but will not work:
An incomplete DTD can be created by the task - but this
one has a few problems:
It doesn't know about required attributes. Only manual tweaking of
this file can help here.
It is not complete - if you add new tasks via
it won't know about it. See this page by Michel Casabianca
for a solution to this problem. Note that the DTD you can download at
this page is based on Apache Ant 0.3.1.
It may even be an invalid DTD.
As Ant allows tasks writers to define arbitrary elements, name
collisions will happen quite frequently - if your version of Ant
contains the optional and tasks, there are two XML
elements named test (the task and the nested child element of )
with different attribute lists. This problem cannot be solved; DTDs
don't give a syntax rich enough to support this.
Again, the FAQ states the DTD is not (yet?) powerful enough to do this, but I found a preliminary work for Ant 1.6 based on Michel Casabianca's work at the AntDTD page on the Ant Wiki. As for me, I do not intend to use it.
Related
So, at work, I frequently have to create virtually identical ant scripts. Basically the application we provide to our clients is designed to be easily extensible, and we offer a service of designing and creating custom modules for it. Because of the complexity of our application, with lots of cross dependencies, I tend to develop the module within our core dev environment, compile it using IntelliJ, and then run a basic ant script that does the following tasks:
1) Clean build directory
2) Create build directory and directory hierarchy based on package paths.
3) Copy class files (and source files to a separate sources directory).
4) Jar it up.
The thing is, to do this I need to go through the script line by line and change a bunch of property names, so it works for the new use case. I also save all the scripts in case I need to go back to them.
This isn't the worst thing in the world, but I'm always looking for a better way to do things. Hence my idea:
For each specific implementation I would provide an ant script (or other file) of just properties. Key-value pairs, which would have specific prefixes for each key based on what it's used for. I would then want my ant script to run the various tasks, executing each one for the key-value pairs that are appropriate.
For example, copying the class files. I would have a property with a name like "classFile.filePath". I would want the script to call the task for every property it detects that starts with "classFile...".
Honestly, from my current research so far, I'm not confident that this is possible. But... I'm super stubborn, and always looking for new creative options. So, what options do I have? Or are there none?
It's possible to dynamically generate ANT scripts, for example the following does this using an XML input file:
Use pure Ant to search if list of files exists and take action based on condition
Personally I would always try and avoid this level of complexity. Ant is not a programming language.
Looking at what you're trying to achieve it does appear you could benefit from packaging your dependencies as jars and using a Maven repository manager like Nexus or Artifactory for storage. This would simplify each sub-project build. When building projects that depend on these published libraries you can use a dependency management tool like Apache ivy to download them.
Hope that helps your question is fairly broad.
I was trying to perform java compilation using ant 1.8.1. Due to the requirement, I have to compile number of java source folders (containing java files) in a loop. These folder names will be derived from the java project mentioned in the property file. From the loop itself I need to perform java compilation. So I used a macrodef where I am passing all the required parameters for java source compilation. Essentially, I have a main build.xml file from where I am calling build_Compile.xml (responsibility of this is to figure out which Java projects to build and their corresponding source folders and perform compilation in loop for each project). To achieve this I use a macrodef defined in a helper file (Helper.xml) file which contains number of macrodef.
However, when I execute the task, I am getting an error which implies that java src path(being passed as parameter) is not being found properly. What I noticed is the path of the build files (where all my build*.xml files reside) is being appended before the java src directory path(passed as parameter in the macrodef). I printed the parameter being passed to the macrodef which looks as expected. Here is the snippet which I am using for java source compilation -
.....
.....
<javac srcdir="#{srcpath}"
destdir="./Temp/build/classes/"
includeAntRuntime="false"
classpath="${classpath}"
includes="${replacedartefacts}">
</javac>
Sorry for the long story. Appreciate any pointer/guideline. Thanks.
I'm a bit confused by the loop idea. There are two ways I can think about this:
You have a single project, but compiling different source directories depending upon the project.
You have a master build.xml that's calling a bunch of sub projects that contain source folders to compile.
In the first example, each <javac> call depends upon already compiled classfiles. In the second scenario, each set of Java sources you're compiling is independent of the rest
You don't give the error you're getting or the value of #{srcdir} which would help.
I notice you have an includes parameter. This is the list of java files to include. I also notice this is a property. That means this cannot be changed once it is set. Why do you have an includes parameter? How will specifying a particular set of files to compile for ALL project affect what you want to do. Is this some value like *.java? Is this something that will be the same for each set of source directories you're compiling?
Could this be an issue with the ${basedir} property? When you use <ant> or <import>, your ${basedir} is set to the calling program's ${basedir} and not to the ${basedir} in the called programs.
Run Ant with the -d parameter. This will produce hundreds of lines of output, but will show exactly what is going on with each call to <javac>. We can give you more help if you also post the exact error message and maybe a bit more information on how your project is setup.
Talking about loops, take a look at the Ant-Contrib tasks, especially the for task. Also look into the Ant subant task. The <for> task gives you a way to easily loop through a bunch of directory parameters. The <subant> task is made for a master build building sub-projects.
I am using ant externally, i.e. I construct org.apache.tools.ant.Project dynamically
in my program: setup its Tasks, Targets etc., then I want to create build.xml file. How is possible? How possible export this project into ordinal ant build.xml?
I've been working with the ant codebase a lot recently, and I'm afraid I don't think this is possible.
Since you're the one generating the project in the first place, it might be easier if you generate the XML at the same time.
I would like to simplify my main build scripts, and I'd like to have the ability to reuse certain common ant tasks as a library, but I'd also like them to be easily available as a package.
For instance, I've got a task which sets up the Flex environment variables that I need to build a variety of projects. I can (And am currently) include those scripts by relative path from another location in source control. But what I want to do is make a single download-able package that I can grab via Ivy that contains all of these generic tasks.
A jar seems the most natural solution, since this is doable from java (Use the class loader to access the file inside the jar.), but I can't seem to find a "native" way in Ant to just get the xml file.
In short, I want to do:
<import file="some.jar!bootstrap.xml">
But that doesn't work.
Is there someway to do this? Any other suggestions for making a library of ant scripts would be much appreciated as well.
From what I understand you're trying to extract a file containing more ant tasks from your jar and then tell ant to execute the tasks in those extracted files. Since the files are static, you'd probably be better off creating actual java Task definitions in your jar and declaring them in your ant build file. However, if you don't want to do that, you can just use the Unzip ant task to extract the resource out of the jar and onto the file system and then use the Ant task to execute the extracted file.
IIRC there's ongoing work in Ant to support this but it's not supported in any published version.
I'm trying to figure out how the DITA Open Toolkit performs DITA to XHTML conversions, and it's difficult since the process is managed by dozens of ant targets spread over multiple ant files.
I need a tool that can provide a visualization of the execution flow plus property dependencies of an ant invocation. VizAnt and Grand only graph target invocations, so I'm looking for something heavier-duty. Ideally, such a tool would identify the order of target invocations, as well as property values live at invocation, and properties, files, directories, classpath entries, etc. that are referenced in the body of a target.
My first thought was to manually graph it all in OmniGraffle, but the complexity quickly became unmanageable. Surely there's something more recent out there?
yWorks Ant Explorer is kind of cool.
Graphical representation of the ANT build targets and dependencies http://www.yworks.com/demos/images/ae1.jpg
Execute code through the GUI explorer of the ANT build file http://www.yworks.com/demos/images/ae3.jpg
Run it by executing the jar file: java -jar antexplorer.jar
It looks like yWorks no longer supports it and have removed it from their website. Links that used to go to Ant Explorer now just take you to their product listing page.
But there appear to be several places that have it available for download:
http://yworks-ant-explorer.software.informer.com/
http://webscripts.softpedia.com/script/Development-Scripts-js/yWorks-Ant-Explorer-29247.html
http://plugins.jetbrains.com/plugin/?idea&id=135