Create Selenium project using Maven - Part 1

It is common knowledge that using the CLI will improve your speed as a software engineer rather than using the GUI based tools.

This is because CLI tools tend to be faster and more resource friendly than using the graphical implementation of the same. For example, using the inbuilt PS terminal inside VS Code is fast. But using the PS terminal directly will be faster. This is because, VS Code is an electron-based application, similar to Atom. And like all electron-based applications, VS Code runs on a web-based framework. This makes the application bulky, slow, and resource consuming. Of course, VS code has been developed to not make these flaws apparent. But when you are deploying servers or other bulky loads, this becomes very apparent.  As a way to overcome this, this tutorial aims at giving a brief introduction to using the CLI to deploy and use maven from the terminal.

Note: Throughout this tutorial, I have used PS (PowerShell), since this is more user friendly and much more easier to use than the CMD terminal due to it's similarity to the UNIX /LINUX terminal.

In order to use Maven from the CLI, you should first have Maven installed in your machine. [Pls get in touch with the System Admin team to install Maven]. You can check if maven is installed by running the following command. 

mvn -v

This will give you the following output:

Once you have checked if you have Maven installed or not, you can proceed to create a maven project. This can be done in two ways:

  • Normal command line mode (Single Command Mode)
  • Interactive command line mode

Normal Command Line Mode:

In this mode, the entire command is given at the very beginning. You can also save this file into a bash script or a .sh file and only change the required values when creating a new project. Once you have changed the values, you can run the script to create a project. The downside of this method is that you have to edit the file every single time you create a new maven project. 

mvn -B archetype:generate -DgroupId='com.cic <mostly com.CompanyName>' -DartifactId='qmall <ProjectName>' -DarchetypeArtifactId='maven-archetype-quickstart' -DarchetypeVersion='1.4'

The above code can be edited as per project requirement. It can also be stored in a .sh or .bat file and run every time you need to create a maven project after editing the contents of the file. 

Once the above script is run, you get the following output:

Once the script has run, you'll get a project with the following folder structure:

Once this is done, you can cd into the project folder and run:

mvn compile

This will compile the project and give you the following tree structure:

Interactive Command Line Mode:

This method is used to overcome the shortcomings of the normal mode. Here, you can set the various values like Artifact ID and such directly in the terminal without having to edit a script each and every time. 

In order to invoke this method, run:

mvn archetype:generate

When you get this, just hit Enter. This will automatically select the quick start archetype. It will list a version list, select 8. It'll select version 1.4. 

Once the archetype version is chosen, it'll ask for the group id. give the group id in the required format. Most often, it is supposed to be com.<CompanyName>. Once the GroupId is set, hit Enter. Then fill out the ArtifactId. This is mostly supposed to be your project name. Then it'll ask for version. Leave it blank to select the default version. Then, it'll ask for package. Leave it blank to select the default package. Then you'll be asked to confirm the configurations. Type 'y' and hit enter.

The new maven project will be created like below:

Cd into the project directory and run the following command to get the proper folder structure. 

mvn compile

These are the basic procedures to create and compile maven project using the CLI. Once this is done, you can open up the project in VS Code using the command: 

code qmall

The maven build tool framework and other nuances will be explained in upcoming tutorials.

Follow Us On

Registered Office

CHG IT CONSULTANCY PVT LTD

STPI Technology Incubation Centre,
2nd Floor, No.5, Rajiv Gandhi Salai,
Taramani, Chennai – 600113,
Tamil Nadu, INDIA

Parent Office

CIC Corporation

2-16-4 Dogenzaka, Shibuya-ku,
Nomura Real Estate,
Shibuya Dogenzaka Building,
Tokyo 150-0043, JAPAN

  +81 03-3496-1571
AboutUs

CHG IT Consultancy Pvt. Ltd. is a subsidiary of CIC Holdings Co. Ltd. Japan. Our company is focused on IT related solutions to reap the benefits of global popularity of Software Industry.

Registered Office
CHG IT CONSULTANCY PVT LTD

STPI Technology Incubation Centre,
2nd Floor, No.5, Rajiv Gandhi Salai,
Taramani, Chennai – 600113,
Tamil Nadu, INDIA

CIC Corporation

2-16-4 Dogenzaka, Shibuya-ku,
Nomura Real Estate,
Shibuya Dogenzaka Building,
Tokyo 150-0043, JAPAN

+81 03-3496-1571