How can I build Maven dependencies from Ant Java classpath? - ant

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.

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.

How to get all dependency jars from build.xml

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.

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.

Maven run ant builds in subdirectories

I have multiple JavaFX 2.0 apps (built with the default ant scripts generated by netbeans 7.0) which I want to be wrapped up into a war by a maven pom in the parent directory.
The war-building pom has lots of ant tasks in the compile phase that look like this:
<ant antfile="FXapplication1/build.xml" target="jar"/>
But when I go to run 'mvn compile', I get this error from ant:
"C:\path\to\warbuilder\FXapplication1\nbproject\build-impl.xml:209: Must set src.dir"
The ant script builds fine when explicitly called inside its own directory, so I'm assuming that the problem is that it's looking in the war builder's local directory for its source files, rather than looking for them relative to the build.xml. Is there a way to specify a working path for a given ant task?
Try making the JavaFX apps modules of the warbuilder app, each with their own pom which executes <ant antfile="build.xml" target="jar"/>,
rather than running <ant antfile="FXapplication1/build.xml" target="jar"/> from the parent.
The parent should list the children as modules, they will then be executed as part of the parent build process.

Is there an ivy/ant equivalent to mvn jar-with-dependencies?

With maven-assembly-plugin it's possible to package a project into a single jar w all the dependencies.
I have not used it by myself, but one-jar seems to do what you need. It also has an ant task and offers an ant example.

Resources