James P.
James P.

Reputation: 19617

Applying Maven to a project

I've been asked to apply Maven to a project. After browsing a dozen sites it appears that it's quite vast and I'm not familiar as I'd like with similar tools like Ant. Why is it used/preferred and what does it offer over a standard Eclipse project? Also, how could it be added to an existing project?

Upvotes: 0

Views: 132

Answers (4)

musiKk
musiKk

Reputation: 15189

If you use the M2Eclipse plugin from Sonatype, it's just a matter of right clicking the project in the package explorer and choosing Enable Dependency Management in the Maven menu. You are also advised to adjust the directories that contain the sources to the Maven standard directory layout but if you absolutely can't, you can configure that later.

Apart from that: Well, look for tutorials and documentation (for example there is the free book Better builds with Maven. Maven is very complex (yes, I don't think it is simple) and very powerful.

Upvotes: 1

Raghuram
Raghuram

Reputation: 52665

Why is it used/preferred and what does it offer over a standard Eclipse project?

It is a build tool which can build your project without the need for an IDE like Eclipse. It can create a jar or war or other artifacts from the source, performing a bunch of steps like compilation, running unit tests, etc.

Where maven scores over ant is in managing third-party dependencies and in convention over configuration (which mean less lines of build script if you follow convention).

Also, how could it be added to an existing project?

  • You start by creating a new maven project, following the step here.
  • Place it in the root folder of your project
  • If your source and resource files do not follow maven folder convention, update maven properties suitably referring to this documentation.
  • Run mvn package
  • It will fail if it needs any third party dependencies, which you can add as specified in the doc
  • With some trial and error, you should have your project running with maven, possibly, much quicker than if you were to set up the same with ant.

Others are already provided sufficient resources to read more about maven.

Upvotes: 3

Grooveek
Grooveek

Reputation: 10094

Maven is a great tool when you know how to use it. Maven (at core) is a dependency manager.

You include in your pom.xml (similar in function to the build.xml from Ant) all the librairies your project depends on (example : apache commons) along with their version and Maven get them directly from a repository (by default, the central maven repository)

Then you do not have to manually install any jar to make your project work. All is downloaded and cached on your local machine. You can even create an enterprise repository where you put all the jars needed by your company

Maven uses the concept of artifacts which are pre-built library projects with their own dependencies

To mavenize a project, you'll have to write a pom.xml describing your project (examples are numerous), get rid of your libs directory (or whatever classpath you described under Eclipse) and add all your dependencies to your pom.xml

You could also check Mavenizer for a first-start

But Maven is a lot more what i've just said. Read the docs, read poms from librairies and you'll get used to it quickly ;-)

Upvotes: 1

Puce
Puce

Reputation: 38152

I suggest to start reading here: http://www.sonatype.com/books/mvnref-book/reference/public-book.html

Upvotes: 1

Related Questions