Error: M2_HOME is set to an invalid directory - maven

I got this error
Error: M2_HOME is set to an invalid directory.
M2_HOME = "C:/Users/joanet/.m2/repository"
Please set the M2_HOME variable in your environment to match the
location of the Maven installation
but C:/Users/joanet/.m2/repository is a valid directory !

Yes, your folder is valid, but this is not the folder you want to point to.
I think it should point actually where the error messages says to you, to your maven installation folder (something like this)
C:\development\maven\apache-maven-3.1.0
You are currently pointing to your local repository, something which is usually configured in the settings.xml of maven (in the conf folder of the previous url route).

Such issue appears also, if you have 2 or more mavens installed. Try to delete old versions to have only latest.

Check the System Variable M2_HOME and PATH values set in different maven installation locations.

If your java version is 8
you can remove "MAVEN_OPTS : -Xms256m - XMX512m" environmental variable and check "mvn -v".
because java 8 does not support for the above config.

This happened to me when I tried to upgrade to new Maven version.
Below are the steps you should follow when setting up Maven on Windows. If something is missing, the above error will trigger (most probably the 2nd or 3rd step may be missing for mentioned error).
Step 1:
First, download(Apache Maven download link:
https://maven.apache.org) and extract it to C:\Program Files
Step 2:
Go to Environment Variables and Define below varibles in System variables
M2_HOME - C:\Program Files\apache-maven-3.3.9 MAVEN_HOME -
C:\Program Files\apache-maven-3.3.9
Step 3:
Make sure to add the maven bin file to Path varible in System variable
C:\Program Files\apache-maven-3.3.9\bin
Step 4:
Once you are done with configurations, make sure to restart the project.
Step 5:
Check whether the Maven is configured successfully using below command
mvn -version

Related

Error while run the maven framework through command prompt but it's running fine with eclipse

I faced the issue with the surefire plugin "2.19.1" as below. I have tried with the version 2.19.1,2.12.4,3.0.0-M1
You're maven seems to be corrupt. Assuming you're on a windows machine:
1) set M2_HOME environment variable to the folder where maven is. (if in doubt download it and put it somewhere, it's just a java program.
2) set JAVA_HOME environment variable to the folder where your java is.
3) add %JAVA_HOME%/bin:%M2_HOME%/bin to the start of your PATH environment variable.
4) Make sure your ~/.m2/ folder has a settings.xml in it, you can use the one from the maven download to start. (you may need to add the proxy details)
5) Test with
mvn -version
6) You can clear your local repository by deleting files in ~/.m2/repository if you've not done much and have a reasonable network just blow the whole thing away.

Maven isn't installing correctly

I am trying to install maven v3.5.4 onto my computer and whenever I try the 'mvn -version' command, I get
'mvn' is not recognized as an internal or external command,
operable program or batch file.
I have looked up multiple tutorials on how to do this, and they are giving nearly the same information. Add system variables M2 and M2_HOME, then append a directory to the Path system variable. I have the System Variables configured to the following:
M2:
Name: M2
Value: C:\Program Files\Apache\maven\bin
M2_HOME:
Name: M2_HOME
Value: C:\Program Files\Apache\maven
MAVEN_HOME:
Name: MAVEN_HOME
Value: C:\Program Files\Apache\maven
Path:
Name: Path
Value: %M2_HOME%\bin;%JAVA_HOME%\bin
I have seen people saying that there should be a .exe or .bat file inside the bin directory. I do not have any of these. I only have 4 files inside this folder.
This could perhaps be the issue. The path to my Maven directory is:
I have the following maven related system variables:
And my Path variable is:
I'm not sure how to fix this issue so if anyone knows, please let me know.
Add a variable MAVEN_HOME like:
Name: MAVEN_HOME
Value: C:\Program Files\apache-maven-3.3.9\bin
In your case, the M2_HOME path is not correct. Hence It must not be working. Try to give the correct path to the bin folder.
First you have to download maven from here, preferably the latest version and install it.
Then, you have to set the Path variable for Maven.
Go to Start and search for 'Edit the system environment variables'.
Choose the environment variables option and like you do in the example you provided, leave M2_HOME as you have it, delete M2 and change the one in your path to: %M2_HOME%\bin\;
Also, please make sure that you are editing the system environment variables.
As I it says on the download page of the version you are trying to install: "Maven 3.3+ require JDK 1.7 or above to execute". So make sure you have the right version of java.
If this does not work, then I don't think someone on Stack-Overflow can help.
Install Java
Download Java SE Development Kit from Oracle's website and install it
Browse via windows search to Environment Variables
Press New... in System variables list
Insert JAVA_HOME to Variable name
Insert its path to Variable value (e.g: C:\Program Files\Java\jdk1.8.0_102)
Press Edit to Path and then press New
Insert %JAVA_HOME%\bin
Open cmd and type java -version to check if it is ok
Install Maven
Download Maven Binary zip archive from Apaches's website
Unzip the folder and move it to C:\Program Files
Browse via windows search to Environment Variables
Press New... in System variables list
Insert MAVEN_HOME to Variable name
Insert its path to Variable value (e.g: C:\Program Files\apache-maven-3.6.2)
Press Edit to Path and then press New
Insert %MAVEN_HOME%\bin
Open cmd and type mvn -version to check if it is ok

Jenkins ERROR: Failed to parse POMs java.io.IOException: Cannot run program error=2, No such file or directory

In jenkins I am forcing the execution to happen in one of the slaves.
in jenkins configuration I have updated the JAVA_HOME and MAVEN location to the location where its installed in the slave. When I start the build in jenkins I receive the following error
ERROR: Failed to parse POMs
java.io.IOException: Cannot run program "/home/jmeter/jdk1.8.0_112/bin/java" (in directory "/home/jmeter/apache-jmeter-2.13/bin/workspace/MyProject"): error=2, No such file or directory
PS : /home/jmeter/apache-jmeter-2.13/bin/workspace/MyProject - This directory got created and does exist in the slave machine
Can someone please share their expertise in resolving it ?
I needed to add Tool location of JDK8 for machine i run test on.
looks like there is a problem in the MVN installation. PLS make sure in the global config that you have the required mvn installation.
jenkins-->manage-->configure look for Maven installations and use automatic installation for the required version
make sure you have the JDK installation in the same config file
After wasting one day trying with different things going through different suggestions I got nothing. But, it was actually very simple. Please add the JDK path as bellow to your JDK Path in Jenkins-
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
You should assign the JDK in the Meta Data,The JAVA_HOME of system is not work for build.
Check your Maven version selected into the Manage Jenkins->Global Configurations->Maven->Maven Installations->Install from Apache->Version is same as installed on the server and your maven project.
You might have left out a few dependencies resulting in this issue.
Go back and download java and set the path as before:
To download, use
$yum -y install java-1.8*
Set the path to
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.amzn2.0.1.x86_64
Note: Get your path using command
find /usr/lib/jvm/java-1.8* | head -n 3
This got resolved after adding maven_home and providing the path in the global properties.
Go to: Jenkins ⟶ Manage Jenkins ⟶ Global Properties ⟶ MAVEN_HOME [C:\Program Files\Apache\apache-maven-3.6.3-bin\apache-maven-3.6.3]
Just in case someone else runs into this. I was getting this error because someone setup the JDK in Global Tool Configuration to download a windows version of the JDK, but my instance of jenkins is running on linux. Once I made the change to use a linux version of the JDK my issue was resolved.

maven is not a valid Maven home directory

I get this error message when I try to run my code. The default Maven Home Directory was the m2 folder. I tried using override and I selected where all the Maven files are in the m2 folder and it still gave me this error message. I'm unsure how to fix is any help will be much appreciated.I
maven is not a valid Maven home directory
This error message means that the folder named "maven" that you've chosen does not contain maven installation.
The default Maven Home Directory was the m2 folder.
Normally, by default you'll see either the embeded maven or the value of M2_HOME environment variable. This makes me think that maven is not configured correctly on your machine.
In command prompt, to see where M2_HOME points run: echo %M2_HOME%
Then make sure that this value is either empty or points to where maven is installed.
Finally, make sure maven is installed in folder different than .m2 (where actually it stores its settings).

mvn is not recognized after installation Maven 3

I have some problems with my maven 3 installation.
I have downloaded maven 3.0.3 and extracted it to a folder.
I set the following environment variables.
M2_HOME: C:\a few folders\apache-maven-3.0.3
M2: %M2_HOME%\bin
JAVA_HOME: C:\Program Files\Java\jdk1.6.0_25
Path: %JAVA_HOME%\bin; %M2%
I get a message that the command is not recognized when i type "mvn" in the command line. Any ideas?
Maven 3.0.3 and later doesn't need the M2_HOME variable.
The following environment variable changes are sufficient to run Maven from the command-line:
Setting JAVA_HOME to the Java jdk directory (eg. C:\Program Files\Java\jdk1.6.0_29)
Setting PATH to include the Maven bin directory.
Everything looks OK.
I don't know if there should be a space after the semicolon and %M2%. This might be your problem.
Make sure you typed a "a few folders" correctly.
Try this:
Add(create) these new variables at the SYSTEM VARIABLES (M3_HOME and M3):
M3_HOME: C:\maven_installation_folder\
M3: %M3_HOME%\bin
Include at: "CLASSPATH" and "Path" variables
CLASSPATH: other_variables;%M3%;
Path: other_variables;%M3%;
Go to Command Prompt (cmd) and type:
mvn -version
Maven 3.0.3 and later doesn't need the M2_HOME variable. So no need to add that.
I did the following in the Windows System variables and it works:
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_31
Path=C:\Program Files\Java\jdk1.8.0_31\bin;C:\Selenium 3\Maven\apache-maven-3.3.3\bin

Resources