Build a simple Maven Project

Follow the below steps to create a new maven project in IntellijIdea:

1) Click on File -> New -> Project

2) Select Maven and click on Next button

3) Enter your project name, GroupId, ArtifactId as shown below and click on Finish button.

 

4) Maven project is created with default structure.

5) Testing the POM file

Open a command prompt and change the directory to project root directory. Then execute this command:

mvn clean

The mvn clean command will clean the project directory for any previous temporary build files. Since the project is all new, there will be no previous build files to delete. The command will thus succeed.

6) Create a Java class file

Inside the src/main/java directory, create a new package – helloworld. Create a new class inside the package and put the below code inside the class.

7) Build the project

Open the command prompt and change the directory to project root directory. Then execute this command.

mvn package

The mvn package command instructs Maven to run the package build phase which is part of the default build life cycle

Maven will compile the Java source file and create a JAR file containing the compiled Java class.

The following jar file will be created:

sample-1.0.jar

 

Share

Bijan Patel

Founder & Creator of QAScript | 12+ years of IT Experience | Full Stack Automation Engineer | Blogger | Trainer

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!