How to get all dependency jars from build.xml - ant

I have several very big ant build.xml files.
Someone know tool or program for get all dependency jar files from build.xml ?

Please check How To Check Dependencies Between Jar Files?.
http://www.jboss.org/tattletale or jdepend could help in getting dependencies between jars.
If you want to extract dependencies from a given build.xml , one option is to write XML parser and process ant file. Not an easy task. Another option will be write a listener for each build task. If the task is javac then query its classpath.

Related

Download dependencies from Ivy.xml

I have an ant project with ivy dependencies in it. Unfortunately my Intelij IDEA does not understend ivy dependencies. But ant builds project well. I want to download all dependencies to one folder and add jars explicitly to project.
How can i download all dependencies automatically?
As described here http://ant.apache.org/ivy/history/latest-milestone/ant.html
During ant build ivy dependencies downloads to "cache". If i'll found this cache path i can took jars from there.
Look at what ant is doing. If its a well written ant script you'll find (do an ant -p -v) targets specifically for retrieving the ivy dependencies. Also you may inspect the build.xml and watch out for retrieve tasks probably in the ivy namespace.

executable jar from groovy sources

I could not find a proper answer to the following question : while creating an executable jar from groovy compiled sources, I cannot simply include groovy-all-version.jar in a lib directory (as I would do in java) but I need to extract all the classes from the jar and package them with my own classes as otherwise I get an exception. This actually is the case with all libraries I may want to use.
Not clear ? Let's see an example.
toto.groovy belonging to package titi is compiled in a build directory which looks like this :
build
lib
groovy-all-1.8.4.jar
titi
toto.class
and a MANIFEST.MF that will be included in the jar contains the lines:
Main-Class: titi.toto
Class-Path: lib/groovy-all-1.8.4.jar
Executable jar creation is done with the following ant target in build.xml:
<jar destfile="${build.exe.dir}/${exe.name}"
basedir="${build.dir}"
manifest="${src.conf.dir}/MANIFEST.MF"
/>
Now if I try to execute the jar, I get
$ java -jar target/toto.jar
Exception in thread "main" java.lang.NoClassDefFoundError: groovy/lang/Script
(I've checked that the groovy.lang.Script class exists.)
On the other hand, if I unjar groovy-all-version.jar in build by adding an unjar task before the jar, execution goes fine. OK, it works, but it slows down the compilation process and I'd like to understand...
Any feedback is highly appreciated.

How to build exploded jars using Ant task?

Kindly suggest how to build exploded jars using Ant task?
Thanks.
An exploded jar is simply a directory which has the same structure as a jar file. Just use copy, for example, to put all the files you want in this directory.

Can we use pom.xml into ANT

I know that, we can very well use ANT and Maven together to build the project.We can run ANT scripts through Maven's POM.xml. But my question is can we run pom.xml through ANT's build.xml ?
i.e. can we create maven build from build.xml
Yes, using maven ant tasks.
The page lists out multiple maven tasks which can be integrated into an ant build script, thus combining the features of both. To take an example, there is the mvn task, which as documented can do a full maven build from ant.
<artifact:mvn mavenHome="/path/to/maven-3.0.x">
<arg value="install"/>
</artifact:mvn>
Besides this, there are
Dependencies task
Install and Deploy tasks
Pom task
each described with examples.
Maven and ANT are very different build tools. In ANT you write all the logic yourself, whereas a standard build process is "baked in" with Maven.
The POM file contains no logic, instead it contains a series of declarations about your project.
If you understand well how Maven works, it is theoretically possible to take a POM and generate an ANT build that emulates the behaviour of the Maven build. I'm not aware of any solution which can easily convert in the other direction, mainly because ANT is missing Maven functionality, such as dependency management.
Instead of trying to convert an ANT build into Maven, I'd recommend that you keep your existing build logic and delegate the management of your classpath to the ivy or Maven ANT tasks. These tools also provide tasks to publish your build output to a Maven repository, enabling your project to share with other projects using Maven.
Finally, I'm an ivy advocate and wrote an ant2ivy script which can assist in upgrade process. It creates an initial set of configuration files for downloading your projects dependencies from the Maven central repository.

How can I build Maven dependencies from Ant Java classpath?

Using Maven Ant Tasks, I see lots of examples that build Ant classpath from Maven dependencies, but what about the other way round?
I have a carefully tuned Ant project that builds the Java task classpath from all the jars in my lib directory. How can I use Maven-Ant-tasks to use my classpath to build Maven dependencies?
I would rather not do each jar file individually (my last resort).
Is there a better way?
If you're working on converting from Ant to Maven, just bite the bullet and write out your <dependencies> section to match your ant classpath. You only have to do it once, and you'll thank yourself many times over.

Resources