Wednesday, January 22, 2014

Create Maven project from command line

This post shows how to create a Maven project from command line. Creating a Maven project from command line is note a difficult task. Following are the steps.

  1. Create a directory "testApp" and move into that directory
  2. Run the following command, which will do some downloading from the repository
    mvn archetype:generate
  3. Then you will be asked to select a preferred configuration from the given list. It will prompt with a default archetype "org.apache.maven.archetypes:maven-archetype-quickstart" selected. No need to enter a value. Just press enter for the moment.
  4. It will prompt you to select the version of the archetype. By default the latest is selected. No need to enter a value. Just press enter.
  5. It will prompt you for several other inputs
    • Define value for property 'groupId': : com.example.testapp
      • This will be the package id
    • Define value for property 'artifactId': : mytestapp
      • This will be the name of the final .jar file and whole project will be created inside a directory having this name
    • Define value for property 'version':  1.0-SNAPSHOT: :
      • No need to give any input, just press enter
    • Define value for property 'package':  com.example.testapp: :
      • No need to give any input, just press enter
    • Confirm properties configuration:
      groupId: com.example.testapp
      artifactId: mytestapp
      version: 1.0-SNAPSHOT
      package: com.example.testapp
       Y: : Y
      • Confirm the given information by entering 'Y'
  6.  You will see the following out put or similar
    [INFO] ----------------------------------------------------------------------------
    [INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.1
    [INFO] ----------------------------------------------------------------------------
    [INFO] Parameter: groupId, Value: com.example.testapp
    [INFO] Parameter: packageName, Value: com.example.testapp
    [INFO] Parameter: package, Value: com.example.testapp
    [INFO] Parameter: artifactId, Value: mytestapp
    [INFO] Parameter: basedir, Value: /home/<custom-path>/testApp
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] project created from Old (1.x) Archetype in dir: /home/<custom-path>/testApp/mytestapp
    [INFO] ------------------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 2:58.495s
    [INFO] Finished at: Wed Jan 22 01:29:20 IST 2014
    [INFO] Final Memory: 13M/981M
    [INFO] ------------------------------------------------------------------------
  7. A new directory structure along with a pom.xml file is now created. This directory structure and the configurations inside the pom.xml is selected by the archetype. As we didn't specify any archetype, the default "org.apache.maven.archetypes:maven-archetype-quickstart" is used and project is configured according to that.
  8. At this stage you have success fully created a new Maven project using command line.

No comments:

Post a Comment