18

I've recently been asked to mavenize an existing project, and I don't know exactly what that means. On the maven website it outlines how to create a maven project from scratch, but what if I've already got a substantial amount of code?

I'm comfortable working on the command line or in Eclipse/Netbeans. I know there are a lot of plugins for the 2 IDE's that make this kind of thing easier but I don't know where to start.

Is there anything more to it than just writing a pom file that has all the dependencies in it?

skaffman
  • 398,947
  • 96
  • 818
  • 769
stinkycheeseman
  • 43,437
  • 7
  • 30
  • 49

4 Answers4

17

To "Mavenize" simply means to write a POM (and possibly move code around) so that it builds in Maven.

Often the easiest way to do this is to restructure your code slightly so it matches Maven conventions (e.g. move "sources" to "src/main/java", and explicitly split up separate modules). You can ignore the conventions, and tell Maven how you're storing your classes etc., but in general a small bit of pain up front to make most of Maven then work "out of the box" is worth investing in.

Chances are the vast majority of your Ant (or similar) file is boilerplate, which was the idea behind Maven in the first place. However, there may be some bespoke stuff in there (e.g. test classes that start with "TestIntegration" should only be run on nightly builds) which you'll need to reproduce in Maven.

But yeah, in general it means to take the existing functionality of a build, and reproduce that same functionality using Maven.

Andrzej Doyle
  • 102,507
  • 33
  • 189
  • 228
  • Ah nice, so it's simply an organizational thing. I'm nervous of messing up the people who don't use maven, but I suppose it's easy enough to reflect my changes in the build.xml – stinkycheeseman Jul 30 '10 at 15:39
  • It would normally be unusual to have two build systems both able to build a project; is there any reason why some people wouldn't be picking up Maven? But in any case, you're right - Maven favours "convention over configuration" so it's mainly organisational, and you can definitely update the build.xml to work with the new locations. – Andrzej Doyle Jul 30 '10 at 15:52
  • Alright, cool. I'm assuming everyone will convert to maven but initially I don't want to break anyone's current configurations. – stinkycheeseman Jul 30 '10 at 15:55
  • 4
    Having two builds in parallel is actually a common strategy for a migration (people using Ant can keep using Ant until the Maven build is fully functional). And the common approach is indeed to reorganize and refactor the Ant project to match Maven's conventions and rules. – Pascal Thivent Jul 30 '10 at 20:37
4

It means to reorganise the projects code and resources to conform to the maven model. This use of 'convention over configuration' allows the standard maven tools to operate on your codebase.

pauljwilliams
  • 19,079
  • 3
  • 51
  • 79
0

In addition to what is said.

One can always convert an existing java project to a maven project with eclipse IDE, m2eclipse plugin supports such feature or option, as follows: After installing m2eclipse plugin and restarting eclipse. Right click java project --» configure --» convert to maven

You will have a generated pom to start with, almost always it needs modifications to match the projects dependencies and repositories if those dependencies aren't in the maven central repo.

E_X
  • 3,722
  • 1
  • 14
  • 15
0

Simply, just add the pom.xml file under your root (context) project folder. This will make your project as Mavenize project. Once you have added the pom file, then you can execute maven build life cycle commands from IDE terminal.

These maven life cycle commands associated with default maven plugins. So, below given basic declarations enough to start any simple Java project with Maven build.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>AsyncService</artifactId>
    <version>1.0-SNAPSHOT</version>

</project>
ARK
  • 1
  • 1