maven is not a valid Maven home directory - maven

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).

Related

maven directory not found in Jenkins?

I am doing auto deployment of Java Application using Maven and Jenkins, but it is getting failed.Here is the console output:
I have set the environment varaibles and also downloaded and configure all the required plugins. Need help to solve this issue.
Thanks
First of all: Please copy/paste messages instead of using images.
Secondly, the message said that you probably misconfigured the directory for the settings.xml. The settings.xml is usually in the directory .m2 in the user directory, but it can also be supplied from somewhere else.

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.

Apache Maven is not configured properly into System vairable

I have latest version of Apache Maven 3.3.9 residing in my drive downloaded from here. I need it for configuring Appium tool to perform automated testing of Android applications. I have Maven plugin already configured with my Eclipse IDE. I went through few articles and got to know that I have to configure Maven into system variables as well. I set system variables, path for it as below.
M2HOME = C:\Program Files (x86)\Apache\apache-maven-3.3.9
M2 = %M2HOME%\bin
path = C:\Program Files\Java\jdk1.8.0_31\bin;%M2%
I tried running mvn , mvn -version from cmd prompt to check successful configuration of Maven but it gave me nothing. I tried navigating to the bin folder and re run the command but still the result is same. I even changed my path variable to have absolute path of Apache Maven i.e path = C:\Program Files (x86)\Apache\apache-maven-3.3.9\bin
To be further sure I copied the Apache Maven to a different folder just because it had spaces in between Program Files and Program Files (x86) but still the command prompt is as below:
I had followed above steps referring various articles in google. I'm not getting if I have committed any unseen mistake.
P.S: I have even tried above commands with cmd running as an administrator
Try mvn --version (with two dashes). mvn -v should also work. If Maven is not being executed at all, I suggest you try mvn.bat.
Some Command Prompt configurations will refuse to run .bat-files without the extension unless you explicitly tell them to.
It's probably a good idea to run where mvn in your Command Prompt as well. You should get this:
<YOUR_MAVEN_HOME>\bin\mvn
<YOUR_MAVEN_HOME>\bin\mvn.bat
<YOUR_MAVEN_HOME>\bin\mvn.cmd
if everything it set up correctly.
You should define M2_HOME variable. (Not M2HOME). Make sure it looks like this:
You said that you copied your maven to the location without spaces. That's a good idea. But it looks like your Path system variable points to the old location of maven. Make sure to change it. (What is the current location of maven?)
BTW mvn -version works as well as mvn --version

Error: M2_HOME is set to an invalid directory

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

Missing maven .m2 folder

AFAIK maven does not have an installer for Windows, you simply unzip it wherever you like, as explained here.
However in many places there are references to a .m2 folder under the user folder (in Win7 I would guess it to be by default at C:\Users\.m2. Alas I do not have that folder. Is there some command to create this folder? Am I missing something basic?
On a Windows machine, the .m2 folder is expected to be located under ${user.home}. On Windows 7 and Vista this resolves to <root>\Users\<username> and on XP it is <root>\Documents and Settings\<username>\.m2. So you'd normally see it under c:\Users\Jonathan\.m2.
If you want to create a folder with a . prefix on Windows, you can simply do this on the command line.
Go to Start->Run
Type cmd and press Enter
At the command prompt type md c:\Users\Jonathan\.m2 (or equivalent for your ${user.home} value).
Note that you don't actually need the .m2 location unless you want to create a distinct user settings file, which is optional (see the Settings reference for more details).
If you don't need a separate user settings file and don't really want the local repository under your user home you can simply set the location of your repository to a different folder by modifying the global settings file (located in \conf\settings.xml).
The following snippet would set the local repository to c:\Maven\repository for example:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>c:\Maven\repository</localRepository>
...
When you first install maven, .m2 folder will not be present in C:\Users\ {user} path.
To generate the folder you have to run any maven command e.g. mvn clean, mvn install etc. so that it searches for settings.xml in .m2 folder and when not found creates one.
So long story cur short,
open cmd -> mvn install
It will show could not find any projects(Don't worry maven is working fine :P)
now check your user folder.
P.S. If still not able to view .m2 folder try unhiding hidden items.
Use mvn -X or mvn --debug to find out from which different locations Maven reads settings.xml. This switch activates debug logging. Just check the first lines of mvn --debug | findstr /i /c:using /c:reading.
Right, Maven uses the Java system property user.home as location for the .m2 folder.
But user.home does not always resolve to %USERPROFILE%\.m2. If you have moved the location of your Desktop folder to another place, user.home might resolve to the parent directory of this new Desktop folder. This happens when using Windows Vista or a more recent Windows together with Java 7 or any older Java version.
The blog post Java’s “user.home” is Wrong on Windows describes it very well and gives links to the official bug reports. The bug is marked as resolved in Java 8. The comment of the blog's visitor Lars proposes a nice workaround.
Do you have the file system display config set up to show hidden files and folders? If I remember correctly, by default it's hidden. Should be under c:\users\username\.m2.
If the default .m2 is unable to find, maybe someone changed the default path. Issue the following command to find out where is the Maven local repository,
mvn help:evaluate -Dexpression=settings.localRepository
The above command will scan for projects and run some tasks.
Final outcome will be like below
As you can see in the picture the maven local repository is C:\Users\X\.m2\repository
Check the configurations in {M2_HOME}\conf\setting.xml as mentioned in the following link.
http://www.mkyong.com/maven/where-is-maven-local-repository/
Hope this helps.
Is there some command to create this folder?
If smb face this issue again, you should know the most simple way to create .m2 folder. If you unzipped maven and set up maven path variable - just try mvn clean command from anywhere you like! Dont be afraid of error messages when running - it works and creates needed directory.
If I'm right, it's just because you are missing the cd command. Try c:\Users\Jonathan\cd .m2/.

Resources