Maven

 
 
Maven is a Java project management and project comprehension tool. It's primary goal is to make the developers life easier by providing a well defined project structure, well defined development processes to follow, and a coherent body of documentation that keeps your developers and clients apprised of what's happening with your project.

Maven is distributed at no charge for commercial or non-commercial use and is licensed under the Apache License, Version 2.0.

More information about Maven can be found at: http://maven.apache.org

The latest Maven version can be downloaded from: http://maven.apache.org/download.html







Maven 1.0-rc4: Create a simple project.



Information
Before you can create a Maven project you need to have internet access because Maven automatically downloads dependencies (= JAR files) from the remote central repository located at http://www.ibiblio.org.

Maven will only retrieve dependencies, required for building, which are not satisfied. If you are using Maven to build several projects it is likely that those projects share a few dependencies: Maven will let you share one JAR file between any number of projects that require that JAR to build. No multiple copies of the same JAR on your system!

Operating system used
Windows XP Home Edition Version 5.1 SP 2

Software prerequisites
Maven

Procedure
  1. Create a project directory, e.g: c:\mkdir demoproject

  2. If you have internet access via a proxy then you must do the following (otherwise skip this step):

    • Create file build.properties and this file should contain the following lines:

      maven.proxy.host = my.proxyserver.com
      maven.proxy.port = 8080
      maven.proxy.username = your_username
      maven.proxy.password = your_password


    • Move this file to EITHER one of the following locations:
      • ${project.home}/build.properties
        Note: In this example ${project.home} is c:\demoproject

      • ${user.home}/build.properties
        Note: ${user.home} is the same as %USERPROFILE%

  3. Goto the demoproject directory and type:

    c:\demoproject>maven genapp

    You should see (Note: It might take several seconds!):

    :
    Enter a project template to use: [default]
    Press Enter
    Please specify an id for your application: [app]
    myapp
    Please specify a name for your application: [Example Application]
    Demo Maven Project
    Please specify the package for your application: [example.app]
    com.mobilefish.myapp
    build:start:

    genapp:
    [copy] Copying 1 file to C:\demoproject\src\java\com\mobilefish\myapp
    [copy] Copying 3 files to C:\demoproject\src\test\com\mobilefish\myapp
    [copy] Copying 1 file to C:\demoproject
    [copy] Copying 2 files to C:\demoproject
    BUILD SUCCESSFUL
    Total time: 1 minutes 0 seconds
    Finished at: Thu Jul 08 11:30:11 CEST 2004




  4. The following directory structure is created:

    Created directory structure

  5. To compile all java files, type:

    c:\demoproject>maven java:compile

    You should see:

    :
    build:start:

    java:prepare-filesystem:
        [mkdir] Created dir: C:\demoproject\target\classes

    java:compile:
        [echo] Compiling to C:\demoproject/target/classes
        [javac] Compiling 1 source file to C:\demoproject\target\classes
    BUILD SUCCESSFUL
    Total time: 16 seconds
    Finished at: Sat Jul 10 15:31:44 CEST 2004


  6. The following directory structure is created:

    Created directory structure

  7. To create a jar file, type:

    c:\demoproject>maven jar

    You should see:

    :
    build:start:

    java:prepare-filesystem:

    java:compile:
        [echo] Compiling to C:\demoproject/target/classes

    java:jar-resources:
    Copying 1 file to C:\demoproject\target\classes

    test:prepare-filesystem:
        [mkdir] Created dir: C:\demoproject\target\test-classes
        [mkdir] Created dir: C:\demoproject\target\test-reports

    test:test-resources:

    test:compile:
        [javac] Compiling 3 source files to C:\demoproject\target\test-classes

    test:test:
        [junit] Running com.mobilefish.myapp.AppTest
        [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0,07 sec

    jar:jar:
        [jar] Building jar: C:\demoproject\target\myapp-1.0.jar
    BUILD SUCCESSFUL
    Total time: 1 minutes 4 seconds
    Finished at: Sat Jul 10 15:39:47 CEST 2004


  8. The jar file is created at: C:\demoproject\target\myapp-1.0.jar

    To test the created jar file, type:
    C:\demoproject\target>java -cp myapp-1.0.jar com.mobilefish.myapp.App

    You should see the following:

    Hello World!