Category Archives: Maven

[Solved] Maven: No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK

This maven exception occurs  when your Window/Unix environment variable for JAVA_HOME and PATH are pointing to JRE instead of JDK. That’s why maven will not compile code and throw below exception.

Problem

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SpringBootApp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.5.2/maven-install-plugin-2.5.2.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.5.2/maven-install-plugin-2.5.2.pom (7 KB at 2.3 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/25/maven-plugins-25.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/25/maven-plugins-25.pom (10 KB at 10.2 KB/sec)
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ SpringBootApp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ SpringBootApp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\Saurabh Gupta\facingIssuesOnIT\SpringBootApp\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.342 s
[INFO] Finished at: 2018-05-28T15:59:31+05:30
[INFO] Final Memory: 20M/209M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project SpringBootApp: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Solutions

To resolve this issue you can follow below steps by solving command prompt or Eclipse.

Command Prompt

How to Configure Maven in Window and Linux?

Eclipse

  • Right click on project -> Select Properties
  • Select Java Build Path-> Libraries Tab -> Click on Add Library
  • Refer below link for reference.

Eclipse : How to set java path of JDK/JRE?

Advertisements

Maven Connect Timeout from/to Central “https://repo.maven.apache.org/maven2”

Maven Connect Timeout from/to Central “https://repo.maven.apache.org/maven2” happen when you are in VPN and proxy network where your office firewall not allowing to download from outside network.

CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:3.1: ArtifactResolutionException: Could not transfer artifact org.apache.maven.plugins:maven-compiler-plugin:pom:3.1 from/to central (https://repo.maven.apache.org/maven2): connect timed out

Solution  1:

  • Try  after exiting  from VPN Network so that your office firewall not stop you to download dependencies.

Solution 2:

  • Update your firewall proxy settings in ./m2/settings.xml or /maven directory/conf/settings.xml file as below
 <proxies>
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>your.proxy.host</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>

  </proxies>

  • Add same file in your eclipse as below Window -> Preference-> Maven -> User Settings
    maven settings.xml path

Click on Apply and then OK.

  • Go to your project -> Right Click ->Maven ->Update Project -> Check Force Update -> Click on OK

Hope that will fix your issue .

Leave you feedback to enhance more on this topic so that make it more helpful for others.

 

How to create Dynamic Web Application using Maven and Eclipse?

In this below example will show steps to create Dynamic Web Project using maven and import to eclipse.

Maven provide maven-archetype-webapp archetype artifact to create Dynamic Web based application from command prompt.

Pre-Requisite

Go to directory/ workspace where you want to create maven Java project. Below is command to create it.

mvn archetype:generate -DgroupId=com.{group}.app -DartifactId={App Name} -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Example :

mvn archetype:generate -DgroupId=com.facingissuesonit.app -DartifactId=TestMavenWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Because we are creating our first project with maven that’s why it will download lots of jars and dependency from maven repository.

C:\Users\facingissuesonit\workspace-sample>mvn archetype:generate -DgroupId=com.facingissuesissueonit -DartifactId=TestMavenWebApp
-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: C:\Users\facingissuesonit\workspace-sample
[INFO] Parameter: package, Value: com.facingissuesissueonit
[INFO] Parameter: groupId, Value: com.facingissuesissueonit
[INFO] Parameter: artifactId, Value: TestMavenWebApp
[INFO] Parameter: packageName, Value: com.facingissuesonit
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.374 s
[INFO] Finished at: 2017-06-09T16:52:33-04:00
[INFO] Final Memory: 14M/148M
[INFO] ------------------------------------------------------------------------

Above command will create project with name TestMavenWebApp in your current directory and will show directory structure as below.

TestMavenWebApp
-src
--main
---webapp
----WEB-INF
-----web.xml
----index.jsp
---resources
-pom.xml

Project pom.xml will have entry as below.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.facingissuesissueonit</groupId>
  <artifactId>TestMavenWebApp1</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>TestMavenWebApp1 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>TestMavenWebApp</finalName>
  </build>
</project>

Build Project : Go to project directory and run below command to build your project. It will go through all these steps to complete build life cycle as you can see from console logs.It will create war file for your application.

1. validate
2. generate-sources
3. process-sources
4. generate-resources
5. process-resources
6. compile
7. test

mvn package

C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp>mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestMavenWebApp Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ TestMavenWebApp ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ TestMavenWebApp ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ TestMavenWebApp ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ TestMavenWebApp ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ TestMavenWebApp ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ TestMavenWebApp ---
[INFO] Packaging webapp
[INFO] Assembling webapp [TestMavenWebApp] in [C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\target\TestMavenWebApp]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\src\main\webapp]
[INFO] Webapp assembled in [65 msecs]
[INFO] Building war: C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp\target\TestMavenWebApp.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.352 s
[INFO] Finished at: 2017-06-10T14:37:25-04:00
[INFO] Final Memory: 12M/114M
[INFO] ------------------------------------------------------------------------

Now our build is successful and architecture created by maven is ready. Now time to import this project in eclipse.

Import to Eclipse : To import this project in eclipse first we need to convert this project according to eclipse and then import it.

  • Convert to Eclipse Maven Project : Use below command
    mvn eclipse:eclipse -Dwtpversion=2.0
C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp>mvn eclipse:eclipse -Dwtpversion=2.0
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestMavenWebApp Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-eclipse-plugin:2.10:eclipse (default-cli) > generate-resources @ TestMavenWebApp >>>
[INFO]
[INFO] <<< maven-eclipse-plugin:2.10:eclipse (default-cli) < generate-resources @ TestMavenWebApp <<<
[INFO]
[INFO] --- maven-eclipse-plugin:2.10:eclipse (default-cli) @ TestMavenWebApp ---
[INFO] Adding support for WTP version 2.0.
[INFO] Using Eclipse Workspace: C:\Users\facingissuesonit\workspace-sample
[WARNING] Workspace defines a VM that does not contain a valid jre/lib/rt.jar: C:\Program Files\Java\jre1.8.0_73
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "TestMavenWebApp" to C:\Users\facingissuesonit\workspace-sample\TestMavenWebApp.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.608 s
[INFO] Finished at: 2017-06-09T16:54:24-04:00
[INFO] Final Memory: 14M/115M
[INFO] ------------------------------------------------------------------------ 

Import in Eclipse : Follow below steps to import TestMavenWebApp project in Eclipse

Eclipse File -> Import -> General-> Existing Project in Workspace -> Select Project TestMavenWebApp

It will show some compile time issue on index.jsp page because   not attached with any Web Server and also select Java compiler version from facet as given screen.

TestMavenWebApp Project -> Right Click ->Properties -> Project Facets

Select Runtime and Java compiler version as configured in class path. Click on apply and OK.

maven web facet server

Your Project is ready to more development and configured in eclipse . It will have below directory Structure.

Maven Web Project Directory

Run Project:

TestMavenWebApp Project ->Run As ->Run On Server

We will get below screen after successful execution.

Maven Web Run

Leave you feedback to enhance more on this topic so that make it more helpful for others.

How to add 3rd Party/Custom/External Jars to Maven Project?

In below steps will show about to add 3rd party/custom/external Jars in local repository for use in our project builds because these jars doesn’t exist in Maven public repository and required to build project.

Pre-Requisite

To add these jars we can use below command to load in local repository (.m2/repository)

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id>
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

Example : Oracle is 3rd party and it’s jars are available in maven public repository. We can use below command to store in maven local repository and make entry in pom.xml to use it.

mvn install:install-file -Dfile=C:\\Workspace\\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

pom.xml entry for above oracle jar

<dependency>
	<groupId>com.oracle</groupId>
	<artifactId>ojdbc6</artifactId>
	<version>11.2.0</version>
</dependency>

How to create Maven Java Console Project?

In this below example will show you create maven java project from console and import to eclipse.

Maven provide maven-archetype-quickstart archetype artifact to create console based java project from command prompt.

Pre-Requisite

Go to directory/ workspace where you want to create maven Java project. Below is command to create it.

mvn archetype:generate -DgroupId=com.{group}.app -DartifactId={App Name} -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Example :

mvn archetype:generate -DgroupId=com.facingissuesonit.app -DartifactId=test-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Because we are creating our first project with maven that’s why it will download lots of jars and dependency from maven repository.

C:\Users\facingissuesonit\workspace-sample>mvn archetype:generate -DgroupId=com.facingissuesonit.app -DartifactId=test-app -DarchetypeArtifactId=maven-archetype
-quickstart -DinteractiveMode=false

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: C:\Users\facingissuesonit\workspace-sample
[INFO] Parameter: package, Value: com.facingissuesonit.app
[INFO] Parameter: groupId, Value: com.facingissuesonit.app
[INFO] Parameter: artifactId, Value: test-app
[INFO] Parameter: packageName, Value: com.facingissuesonit.app
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\Users\facingissuesonit\workspace-sample\test-app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.133 s
[INFO] Finished at: 2017-06-06T03:55:59-04:00
[INFO] Final Memory: 14M/148M
[INFO] ------------------------------------------------------------------------

Above example command will create project with name test-app in your current directory and will show directory structure as below.

Test-app
-src
--main
---java
----com
-----facingissuesonit
------app
-------App.java
--test
---java
----com
-----facingissuesonit
------app
-------AppTest.java
-pom.xml

Project pom.xml will have entry as below.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.facingissuesonit.app</groupId>
  <artifactId>test-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>test-app</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Build Project : Go to project directory and run below command to build your project. It will go through all these steps to complete build life cycle as you can see from console logs.

1. validate
2. generate-sources
3. process-sources
4. generate-resources
5. process-resources
6. compile
7. test

mvn package

C:\Users\facingissuesonit\workspace-sample\test-app>mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-app ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\facingissuesonit\workspace-sample\test-app\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-app ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\facingissuesonit\workspace-sample\test-app\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test-app ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\facingissuesonit\workspace-sample\test-app\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-app ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\facingissuesonit\workspace-sample\test-app\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ test-app ---
[INFO] Surefire report directory: C:\Users\facingissuesonit\workspace-sample\test-app\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.facingissuesonit.app.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test-app ---
[INFO] Building jar: C:\Users\facingissuesonit\workspace-sample\test-app\target\test-app-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.372 s
[INFO] Finished at: 2017-06-06T04:07:45-04:00
[INFO] Final Memory: 16M/145M
[INFO] ------------------------------------------------------------------------

Now our build is successful. We can use below command in target folder to run test-app project.

C:\Users\facingissuesonit\workspace-sample\test-app\target>java -cp test-app-1.0-SNAPSHOT.jar com.facingissuesonit.app.App
Hello World!

Import to Eclipse : To import this project in eclipse first we need to convert this project according to eclipse and then import it.

  • Convert to Eclipse Maven Project : Use below command
    mvn eclipse:eclipse
C:\Users\facingissuesonit\workspace-sample\test-app>mvn eclipse:eclipse
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-eclipse-plugin:2.10:eclipse (default-cli) > generate-resources @ test-app >>>
[INFO]
[INFO] <<< maven-eclipse-plugin:2.10:eclipse (default-cli) < generate-resources @ test-app <<< [INFO] [INFO] --- maven-eclipse-plugin:2.10:eclipse (default-cli) @ test-app --- [INFO] Using Eclipse Workspace: C:\Users\facingissuesonit\workspace-sample [WARNING] Workspace defines a VM that does not contain a valid jre/lib/rt.jar: C:\Program Files\Java\jre1.8.0_73 [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER [INFO] Not writing settings - defaults suffice [INFO] Wrote Eclipse project for "test-app" to C:\Users\facingissuesonit\workspace-sample\test-app. [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.717 s [INFO] Finished at: 2017-06-06T04:56:14-04:00 [INFO] Final Memory: 12M/114M [INFO] ------------------------------------------------------------------------ 

Import in Eclipse : Follow below steps to import test-app project in Eclipse

Eclipse File -> Import -> General-> Existing Project in Workspace -> Select Project test-app

Maven Java Console Project

How to Configure Maven in Window and Linux?

Configuration in Maven  in Window and Linux required below steps.

  • Download latest version of maven from below link

Download Link : http://maven.apache.org/

Configuration in Window

  • Unzip file apache-maven-X.X.X-bin.zip and change unzip file name like name as maven. It will have directory structure like below
  • window maven directory
    Maven Directory Structure
  • Copy this maven folder to C:\Program Files (x86) directory.
  • Add below Environment Variable by right click on My Computer -> Properties-> Environment Variable/Advance System Settings
    User Environment Variable
    
    M2_HOME : C:\Program Files (x86)\maven
    M2: %M2_HOME%\bin
    PATH : %M2%;
    
    If you already have any value in PATH add %M2%;   after end of value.
    

    It will show as below in screen shot

    maven environment variable window

  • Close all console instances/Command prompt if running and open new command prompt and run below command and will receive output with version of Maven and Java.
    mvn –-version 
    
    C:\Users\FacingIssuesOnIT>mvn --version
    Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T11:41:47-05:00)
    Maven home: C:\Program Files (x86)\maven
    Java version: 1.8.0_73, vendor: Oracle Corporation
    Java home: C:\Program Files\Java\jdk1.8.0_73\jre
    Default locale: en_US, platform encoding: Cp1252
    OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
    

Configure in Linux

Download latest version of Maven and Untar it with below command

tar -zxvf  apache-maven-3.5.0-bin.tar.gz

change name of directory as apache-maven-3.5.0 and set maven environment variable as below for configuration

$ export M2_HOME=/opt/app/facingissuesonit/apache-maven-3.5.0

$ export M2=$M2_HOME/bin
Set below for memory configuration
$ export MAVEN_OPTS=-Xms256m -Xmx512m
with M2_Home path corresponding with the location of your extracted Maven files.

Now append the M2 environment variable to the system path as below:

$ export PATH=$M2:$PATH

To check maven install successfully follow below command

mvn --version

Apache Maven 3.5.0 (r801777; 2009-08-06 15:16:01-0400)
Java version: 1.8.0_73
Java home: /opt/app/facingissuesonit/posbea/jdk-1.8.0_73/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-642.6.2.el6.x86_64" arch: "i386" Family: "unix"