I have experience in Ant, how to get started with maven. Any advantage with maven over ant?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
There's a quite large difference, where ant forces you to create your own targets you will get a default set of targets for maven, e.g.,
clean, install, package
etc without scripting them.Maven promotes that you use a common directory structure for java classes, resources etc. If you do, maven is just on
xml
file where you specify some project metadata such asname
,package
and most importantly depenencies. It provides similar dependency lookup to what ivy does for ant.Based on the standard maven promotes, it becomes very easy for developers to approach and build your projects. With an IDE such as
Netbeans
it's enough to selectopen project
, and then hit theinstall
button to compile and install the project in your local repository.I recommend working with maven the maven way. Doing things differently will often cause more pain than it's worth. Maven offers a plugin structure where you can perform various tasks, such as invoke the ant-library should you need to. If you're actively working with multiple projects (and want project switching to be as easy as possible) maven is a huge leap forward, especially if combined with repository server such as
Nexus
orArchiva
.To get started
Either you can generate your project structure using the
archetype
goal of maven, or you could do it the way I do by copy-pasing an empty template project every time. Then you need the maven binary and the project definition filepom.xml
which I typically also copy paste between projects.A sample is included below. With this sample you'll get the external library log4j, and you automatically get all nececcities to build and package your own project (in this case to a
jar
file).In comparison to Ant what Maven does well is dependency management and standardisation of the build lifecycle.
As for learning a bit more about it, the Maven documentation is pretty readable and thorough.
I'd start by looking at the introductory piece that explains some of the core principles about the difference between Maven and other build tools.
http://maven.apache.org/what-is-maven.html
Then downlod and install maven, open your terminal and type...
Select all defaults and you'll end up with a simple build-able project with one runnable class and a matching test file. Use that as a test project to familiarise yourself with the build lifecycle and dependency resolution process.
Around two weeks ago, I was in the same situation. In my opinion, Maven is a lot more powerful as compared to Ant.
It has a generate command which makes it very easy to start new projects of various kinds (artifacts) and will also build a standard directory structure along with the pom.xml file, thereby taking care of a lot of things that are needed to be written in the build.xml file of Ant.
Managing dependencies is also a lot better. Maven will download dependencies from repos and will store them in a central repo on your system. If a dependency is already present in the local repository, it will take it from there instead of downloading it again.
I use eclipse and maven has a command (
mvn eclipse:eclipse
) which creates the .classpath file in the project directory. So no need to add the libraries again in eclipse.The Getting started guide on the maven website is a good resource and covers quite a lot of stuff -