Category: Maven
Executing Maven Project in windows from Command Prompt
Section-I:
Pre-requisites:
Go to Menu Bar in Eclipse >> Window >> Preferences.
Go to Menu Bar in Eclipse >> Window >> Preferences.
Check if Maven is integrated with Eclipse or No.
[If you download Eclipse Neon Version, by default Maven will be integrated with Eclipse].
[If you download Eclipse Neon Version, by default Maven will be integrated with Eclipse].
If Maven is integrated with Eclipse then we are good to create Maven Project.
If not installed go to Menu Bar >> Help >> Eclipse Market Place and Search by Maven and install required Maven Plugins shown below.
Section II:
Steps to install Maven Jar Files and Setting Path in Environment Variables: https://maven.apache.org/download.cgi
Download below highlighted Zip File.
Once download is completed, unzip it and keep it in any drive in your local system.
It is always good practice to keep it in C Drive.
Now we need to set path for Maven in Environment Variables:
Go to My Computer >> Right Click >> Properties >> Advanced System Settings.
Now Go to Environment Variables and Set Pat as shown below.
[In my case i have kept Maven Jars in C Drive]
Now Add Bin Path of Maven in below Path
highlighted
C:Program FilesMavenapache-maven-3.6.1bin
Once Path is set for Maven in Environment Variables.
Go to Command Prompt and type command as shown below to make sure that Maven is installed or not.
If Maven is installed then we will see as highlighted above and now we are good to execute Maven Project.
Section III:
Now Executing Maven Project from Command Prompt.
To Execute Maven Project from Command Prompt, In pom.xml
Maven Surefire Pluginmust be added.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven–surefire–plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng_sanity.xml</suiteXmlFile> </suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
Now Go to Command Promp
Now Go to Command Promp
Go to Project Folder as shown below
Now Use below commands to execute Maven Project from
Command Prompt
1. mvn clean install : It will execute all test cases as well as it will generate a build. Build will be generated under target folder.
2. mvn clean test : It will execute only test cases and it won’t generate build.
How to solve Maven issue – Could not resolve archetype org.apache.maven.archetypes from any of the configured repositories.
-
Problem: –
Solution:
Steps to follow:
-
Right click on project
-
click on properties
-
java build path
-
select source
-
add, apply then OK
6. Open window preferences
7. open Maven
7. open Maven
8. deselect all dialog box
9. Open window : preferences, open Maven Archetype, click on ‘Add Remote catalog’ and add Catalog file: http://repo1.maven.org/maven2/archetype-catalog.xml
Description: Maven Catalog.
click on properties, go to java build path
click libraries
add external jars
add, apply ok.
Error Resolved!! YEY!
Error Resolved!! YEY!
This is Nazia. I have recently completed my post-graduation. Later I joined Naveen Automation Labs which is one of the best online training programs and improved my automation skills a lot. I face some difficulties while configuring Maven, so I tried some of the possible ways to solve them, hope this will help you as well.
Cheers!
Nazia
-Naveen AutomationLabs
What is <scope> under <dependency> in pom.xml for?
The
<scope>
element can take 6 values: compile, provided, runtime, test, system and import.This scope is used to limit the transitivity of a dependency, and also to affect the classpath used for various build tasks.
compileThis is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.providedThis is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.runtimeThis scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.testThis scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.systemThis scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.import (only available in Maven 2.0.9 or later)This scope is only used on a dependency of type pom in the section. It indicates that the specified POM should be replaced with the dependencies in that POM’s section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.
Cheers!
Naveen AutomationLabs