Home » Enterprise Java » Maven » Apache Maven Eclipse Project Creation Using Archetype Example

About Mary Zheng

Mary Zheng
Mary has graduated from Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She works as a senior Software Engineer in the telecommunications sector where she acts as a leader and works with others to design, implement, and monitor the software solution.

Apache Maven Eclipse Project Creation Using Archetype Example

1. Introduction

Eclipse is a Java Integrated Development Environment (IDE). Eclipse has had Maven Integration for Eclipse since version Luna.

Maven Archetype is a Maven project template plug-in. It enables developers to create a new maven project consistently and quickly.

Eclipse IDE comes with nine most commonly used archetypes. Maven hosts about over 600 archetype in the remote catalog. I will show you how to import these archetypes into Eclipse IDE.

In this example, I will demonstrate how to create a new Maven project from a Maven archetype in Eclipse IDE.

Want to master Maven?

Subscribe to our newsletter and download the Apache Maven Cookbook right now!

In order to get you prepared for your Maven development needs, we have compiled numerous recipes to help you kick-start your projects. Besides reading them online you may download the eBook in PDF format!

 

2. Technologies Used

The example code in this article was built and run using:

  • Java 1.8.101
  • Maven 3.3.9
  • Eclipse Oxygen

3. Create a Maven Project from an Archetype

3.1 Create a New Web Application Project

Eclipse includes several common archetypes from the internal catalog. In this step, I will demonstrate how to create a Maven project based on maven-archetype-webapp.

Launch Eclipse IDE. Select File->New...->Project...->Maven-->Maven Project and click Next.

Apache Maven Eclipse Project Creation - New Maven Project
Figure 1 New Maven Project

Select “maven-archetype-webapp” from the archetype grid.

Apache Maven Eclipse Project Creation - Select Archetype
Figure 2 Select Archetype

Enter Maven properties: group id, artifact Id, and version. Click Finish.

Apache Maven Eclipse Project Creation - Set up Project Properties
Figure 3 Set up Project Properties

3.2 Demo

In this step, I will build the generated maven project and deploy it under a tomcat web server. It should include a standard maven project, web.xml and index.jsp based on the definition of maven-archetype-webapp.

Open the Eclipse project and verify it.

Apache Maven Eclipse Project Creation - Verify the Project
Figure 4 Verify the Project

index.jsp

<html>
<body>
<h2>Hello World!</h2>
</body>
</html>


It should automatically build. I can deploy it to a tomcat server. Click here for the detail instructions.

Apache Maven Eclipse Project Creation - Deploy to Tomcat Server
Figure 5 Deploy to Tomcat Server

After the tomcat starts, go to http://localhost:8080/archetype-demo. It should display “Hello World!”

Apache Maven Eclipse Project Creation - Demo Web Server
Figure 6 Demo Web Server

4. Import an Archetype from Maven Remote Catalog

Maven hosts a remote archetype catalog with over 600 commonly used archetypes. Click here to see these archetypes in detail. In this step, I will show you how to import archetypes from a maven remote catalog into Eclipse.

Launch Eclipse IDE, Click Windows -> Preferences -> Maven -> Archetypes. Click Add Remote Catalog.

Apache Maven Eclipse Project Creation - Add Remote Catalog
Figure 7 Add Remote Catalog

Enter http://repo1.maven.org/maven2/archetype-catalog.xml for catalog files. Enter Remote Archetype for description.

Apache Maven Eclipse Project Creation - Remote Catalog
Figure 8 Remote Catalog

Click OK. Now Eclipse has a new remote archetype catalog.

Apache Maven Eclipse Project Creation - Added Remote Archetype
Figure 9 Added Remote Archetype

You can create a maven project from any of these archetypes with the same steps as in step 3.

Apache Maven Eclipse Project Creation - New Project via Remote Archetype
Figure 10 Create New Project via Remote Archetype

5. Summary

In this article, I showed how to import Maven remote archetypes into Eclipse and how to create a new Maven project from the selected archetype.

Most organizations create their own archetype catalog. In that case, developers need to import them into the Eclipse and follow the same step in step 3 to create a new project.

6. Download the Source Code

This example consists of a Maven project generated from maven-archetype-webapp.

Download
You can download the full source code of this example here: Apache Maven Eclipse Project Creation Using Archetype Example
(+4 rating, 4 votes)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar
  Subscribe  
Notify of