Learn How to Create a Java Project using Maven Archetype

0
2130
Java Project

In the last article, we discussed about the use of various Maven Plug-ins. In this article, we are going to discuss and explore the archetype plugins which is used to create project structures. Here, we are going to create a simple JAVA project by using maven-archetype-quickstart plugin. In the following example, we will be creating a maven based JAVA project under C:\MVN_JAVA folder using this folder as the project’s workspace.

Step 1: – Open a window’s command line and change directory to C:\MVN_JAVA

Step 2: – Execute the following Maven command to create a project.

After executing above command on the console, you can observe that Maven has started processing the instructions and has created the complete JAVA application project structure with Maven build as shown below.

Step 3: – After above Maven build is successful, you can navigate to C:\MVN_JAVA directory where you will observe that the plugin has created a complete JAVA project structure with the Maven build, named as “project”. You will observe a standard directory layout as shown below.

MVN_Java_Directory
Description of Folders created by plugin

S No

Folder name

1

project

It is a folder created by the plugin and contains src folder and pom.xml file.

2

src/main/java

It is folder created by the plugin and contains java code files under the package structure (i.e. com/eduonix/project). Here, we had provide plugin option as -Dpackage=com.eduonix.project.

3

src/main/test

It is folder created by plugin that contains test java code files under the package structure (com/eduonix/project). Here, we had provide plugin option as -Dpackage=com.eduonix.project.

4.

com.eduonix.project

It is created as a result of plugin option as

-Dpackage=com.eduonix.project.

Not only these folders are created but, maven-archetype-quickstart plugin has also created the following files as well.
1. A sample Java Source file: – It is the source JAVA file which is named as App.java that contains a main method that is capable of printing the “Hello World!” string on console when executed as shown below.
Path: – C:\MVN_JAVA\project\src\main\java\com\eduonix\project

2. A sample Java Source Junit Test file: – It is the source JAVA Junit Test file which has name as AppTest.java that contains the default Test case, suite, etc. as shown below.
Path: – C:\MVN_JAVA\project\src\test\java\com\eduonix\project

3. The pom.xml file: – The following are the default contents for the pom.xml file which is created by the archetype plugin

Source code for Maven JAVA project structure using the Maven build procedure

Conclusion: –
In this article, we discussed about the use of maven-archetype-quickstart plugin along with a suitable example to create JAVA project structure using the Maven build procedure.

LEAVE A REPLY

Please enter your comment!
Please enter your name here