Creating a Maven project

m2eclipse makes the creation of Maven projects simple. Maven projects can be created in the following two ways:

  • Using an archetype
  • Without using an archetype

Now, we will discuss how to go about creating projects using these methods.

Using an archetype

An archetype is a plugin that allows a user to create Maven projects using a defined template known as archetype. There are different archetypes for different types of projects.

Archetypes are primarily available to create the following:

  • Maven plugins
  • Simple web applications
  • Simple projects

We will now see how to create a simple Hello World! project using an archetype:

  1. Navigate to File | New and click on Other. The project wizard appears and expands the Maven folder. Select Maven Project as shown in the following screenshot and click on Next:
    Using an archetype
  2. The New Maven Project wizard appears. Use the default workspace and click on Next as shown in the following screenshot:
    Using an archetype
  3. The Select an Archetype wizard appears. This shows a list of archetypes available in the Maven repository. New archetypes can be added using the Add Archetypes button. For our case here, let's choose maven-archetype-quickstart as shown in the following screenshot and click on Next:
    Using an archetype
  4. A wizard to specify the Maven coordinates appears. Please fill in the details given in the following table in the screenshot that follows the table and click on Finish:

    Field

    Value

    Group Id

    com.packt.mvneclipse

    Artifact Id

    hello-project

    Version

    Default – 0.0.1-SNAPSHOT

    Package

    com.packt.mvneclipse.hello

    Using an archetype

A sample Maven project has now been created, and it contains a Java file that prints Hello World!. The project has the following structure:

Using an archetype

Using no archetypes

You can create a Maven project without archetypes using the following steps:

  1. Navigate to File | New and click on Other. The project wizard appears and expands the Maven folder. Select Maven Project and click on Next.
  2. The New Maven Project wizard appears. Use the default workspace and check the Skip archetype checkbox as shown in the following screenshot and click on Next:
    Using no archetypes
  3. The wizard to specify the Maven coordinates appears. Please fill in the details, as shown in the following screenshot, and click on Finish:
    Using no archetypes
  4. A skeleton structure, as shown in the following screenshot, will be created, and we have customized it according to the type of application we are building:
    Using no archetypes

Checking out a Maven project

Checking out a Maven project means checking out from the source code versioning system. Before we process this, we need to make sure we have the Maven connector installed for the corresponding SCM we plan to use. Use the following steps to check out a Maven project:

  1. Navigate to Eclipse | Preferences in Mac, else Windows | Preference search in other OS, and search for Maven, expand it, and click on Discovery.
  2. Then, click on Open Catalog. This lists all the m2connectors available in the marketplace. In our case, we are going to use SVN, so choose m2-Subversive, as shown in the following screenshot, and click on Finish. In the screens to follow, click on Next, accept the license, and finally click on Finish to install it. Similarly, we can choose any connector we intend to use for SCM.
    Checking out a Maven project
  3. Like how you create projects, navigate to File | New and click on Other. The project wizard appears. Expand the Maven folder. Click on Checkout Maven Projects from SCM and click on Next.
    Checking out a Maven project
  4. In the next screen, choose the SCM connector SVN and provide the corresponding SVN URL, as shown in the following screenshot, and click on Finish. If you click on Next, it will show the repository structure.
    Checking out a Maven project
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.241.250