Maven

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.

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

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.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button