Maven Course

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21
At a glance
Powered by AI
Maven is a build automation tool used to manage Java projects and automate build processes. It uses a POM (Project Object Model) file to configure build settings and dependencies.

The main maven build life cycles are compile, test, package, verify, install and deploy.

The two main types of maven plugins are build plugins and reporting plugins. Build plugins are used during the build process and reporting plugins are used to generate reports.

1.Maven build process is composed of one build life cycles but has one or more phases.

->Comprehension and Management tool.

2.POM stands for __________ in maven.

->Project Object Model.

3.How to check maven version

->mvn -version

4.Maven is _______________

->Comprehension and Management tool.

5.Command to generate Super POM view

->mvn help:effective-pom

6.Which option stands true for Super POM

->Both the options mentioned

7.What are the minimal coordinate attributes required for pom xlm file

->groupId:artifactId:version

8.What was POM named in maven 1

->project.xml

9.Resources needed for generating build using pom.xml files are

->Source code location, test source location and dependency details

10.Exclusive quantifies boundary range is defined as

->[3.8,4.6)

11.Maven dependencies are stored in ____________

->repository
12.Maven search for dependency in ___________________

->search in all three repositories

13.What does dependency range mean, [2.0.7, 2.0.9)

->2.0.7,2.0.8

14.local repository could be one on the web server.

->F

15.Inclusive quantifiers boundary range is defined as

->[, 3.8]

16.Which of the flow is correct for Build life cycle

->compile->Test->Package->integrate->validate->verify->install->deploy

17.Which of the flow is correct for clean life cycle.

-> Repositories

A build goal is peripheral for a phase when pom binds all goal to the corresponding life cycle

->T

What are the three builds in maven life cycle

->V,c,t

18.Which of the flow is correct for clean life cycle.

->pre clean , clean ,post clean

19.What are the three builds in maven life cycle

->default,clean,site

20.Syntax used for compiling the maven project.


->mvn compile

21.How to get the maven path

->where is mvn

22.While creating maven project, we must enter value for

i. groupId

ii. artifactId

iii. package

iv. version

->I, ii, iii and iv

23.Which plugin is needed to compile project.

->mvn-compile-plugin

24.How can we compile and generate war file using single command

->mvn compile war:war

25.How to generate war file

->mvn package

26.What is archetype

->It is maven project templating toolkit

27.To generate war file using single command,which command in these option is correct

->mvn archetype:generate -DgroupId=com.fresco.play -DartifactId=First-WebApp


-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

28.War files are created for ____________

->Web Application
29.Syntax to create maven project.

->mvn archetype:generate

30.Surefire plugins are used for

->for running Junit test and report generation

31.Which command is used for checking upgrade check

->-Dsurefire.junit4.upgradecheck

32.Maven plugin is

->Both the options mentioned

33.What are the types of maven plugins

->Build and Reporting Plugins.

34.Which command is used for generating Unit test reports

->mvn surefire-report:report

35.Which command is used for skipping the test

->mvn install -DskipTests

36: Which plugin is needed to execute project.

a: exec-maven-plugin

37: List of files generate from maven archetype

a: pom file,main and test folder

mvn archetype:generate to create warfiles

first-war-project will be created with pom.xml file and src folder.


Open pom.xml file and verify that packaging value is changed to war.

In src >main > web app path is create.

Change the folder path by entering cd my-war-project.

To compile type mvn compile.

mvn clean package. to create war file in target folder.

mvn archetype:generate -DgroupId=com.fresco.play -DartifactId=First-WebApp


-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Try creating EAR file yourself with the following hints-

Enter archetype:generate command.

To filter ear type files enter ear.

Select the type of ear file you want.

Enter the latest version of EAR.

Enter groupId as fresco.play.com.

-Type artifactId as first-ear-project.

Enter version: : 1.0-SNAPSHOT.

Enter package as com.fresco.play.


Confirm project by selecting Y.

There are two types of plugins

Build Plugin - Used while executing the build. They are included in <build> element of the POM.

Reporting Plugin - Used while generating the site. They are included in <Reporting> element of the POM.

Some of the frequently used Maven Plugins:

clean - To clear target after the build.

complier - To compile the Java source code.

jar - To generate Java jar file.

war - To generate Java war file.

surefire - To run Junit test and generate a report.

mvn surefire-report: report. --- unit test reports.

JUnit Surefire plugin

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.12</version>

<scope>test</scope>
</dependency>

-Dsurefire.junit4.upgradecheck to perform and check invalid ones

Click Manage Jenkins link from the Jenkins GUI.

Click manage plugins, then select the available tab by searching for GitHub from the search box.

Select the GitHub plugins for installation and click download button.

Select Configure System from the Manage Jenkins page.

Verify that JDK version and JAVA_HOME path is set.

In Git installation, set Path to git executable.

Set Maven Home path in the plugins.

Click Save.

We need to use Git repository in the Jenkins.

Select New Item from the Jenkins GUI.

Enter the Item name as FrescoPlayTest(Name can be of your choice).

Go to Maven project and select the maven project radio button.

Click OK button to confirm maven project selection.

Select Git from Source Code Management.


Set the Repository URL in this box.

Click Advance button twice, and you will get a checkbox option.

Select Skip internal tag. (If it is not checked, Jenkins will create separate tags in the repository.)

Scroll down to Build section, select Invoke top-level, then Maven targets from the drop-down list.

Set Goal as compile. Now we have to set POM path.

Go to Git and find your folder where POM.xml file exists. (e.g. App/pom.xml)

Click Save button.

Console Output. -- to excute the script

Open JMeter GUI. Now, we need to create a Thread Group.

Go to Test right click -> Select Add-> select Threads (Users)-> Thread User -> select Thread Group.

Enter Thread Group Name.

Enter number of Threads (users).

Enter Ramp-Up Period(in Seconds).

Enter Loop count.

Now we can create actual test script or manual record the process.

Add an HTTP Request element.

Go to Thread Group-> Select Add -> Select Sampler->click on HTTP Request.


On HTTP Request page enters valid URL in Server Name or IP box.

Set Port.

Create View Result in Table:

Go to Thread Group-> Select Add -> Add Select Listener-> View Result in Table.

Now, we have created sample test.

Take JMeter script and build it with Maven. We need JMeter Maven plugin.

Create a Maven project for JMeter.

Add JMeter Maven plugin in <build> element of pom.xml file.

<build>

<plugins>

<plugin>

<groupId>com.lazerycode.jmeter</groupId>

<artifactId>jmeter-maven-plugin</artifactId>

<version>2.1.0</version>

<executions>

<execution>
<id>jmeter-tests</id>

<goals>

<goal>jmeter</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

Include your JMeter script to Maven project class under src/test/App.

Change directory to the project from terminal and enter mvn verify.

If the build is proper, it will give us success message as Build Successful.

The current executed result will be stored under target/App/result

Include View - Result Plugins

To get a result in the form of a graph, use JMeter Graph Maven Plugins.

Add this plugin in same pom.xml after JMeter plugins details.


<plugin>

<groupId>de.codecentric</groupId>

<artifactId>jmeter-graph-maven-plugin</artifactId>

<version>0.1.0</version>

<configuration>

<inputFile>${project.build.directory}/jmeter/results/20170319-BlazeDemo Home
Page.jtl</inputFile>

<graphs>

<graph>

<pluginType>ResponseTimesOverTime</pluginType>

<width>800</width>

<height>600</height>

<outputFile>${project.build.directory}/jmeter/results/BlazeDemo
Request.png</outputFile>

</graph>

</graphs>

</configuration>

</plugin>
After this, we need to make some changes in the script, open the JMeter GUI and in Thread group for
Loop Count, increase parameter value to 100. This will help us to execute Thread request 100 times.

To get the output, type mvn jmeter-graph:create-graph in the terminal.

You might also like