Apache Maven is not configured properly into System vairable - maven

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

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.

Jenkins + Maven Manual Installation

I installed Jenkins on to 2 new machines no-problemo!
But, when attempting to integrate Maven, I am having "command not found" in my Jenkins log, yet I can run mvn no problem in the command line.
So, I thought it was a PATH issue - so I added the /bin and also the / (of the location where Maven is extracted to), yet I'm still getting the error.
I tried adding the PATH to my ~/.bash_profile as well, so my current PATH is:
$PATH:/usr/local/bin:/Users/jenkins/apache-maven-3.5.2/bin:/Users/jenkins/apache-maven-3.5.2
Still, Jenkins will not find Maven. I do NOT want to globally install Maven, as it may affect the other 5 build servers we have that are working with Maven correctly (not sure how it's working).
The issue was resolved by simply re-connecting the Jenkins Slave. Thanks for your feedback!

MAVEN - Setting Path in Redhat so the maven commands can be run from anywhere

I have just installed Maven on Redhat, the apache-maven-3.3.9 is located in /root/, I ran the following command to set the path (JDK java home path already set and when I type $PATH the below path does show, along with when I type mvn --version):
export PATH=/root/apache-maven-3.3.9/bin:$PATH
The project I want to build with Maven is also in /root/ however, I cannot use the maven commands within the project or anywhere else except for /apache-maven-3.3.9/bin directory.
Any help would be much appreciated!
You need to add it to your ~/.profile file.
export PATH=$PATH:/root/apache-maven-3.3.9/bin
so that when you exit the terminal and start a new terminal instance path is not lost

Couldn’t find any executable in apache-maven-3.3.3

I have a windows jenkins slave and I have download apache-maven-3.3.3 on it.
It is located C:\Users\myUsername\Desktop\apache-maven-3.3.3 This is copy and pasted from the windows explorer on my Windows slave.
Then when I point at this location in Jenkins and run a build. I get this error
Couldn’t find any executable in C:\Users\myUsername\Desktop\apache-maven-3.3.3
I have also tried Couldn’t find any executable in C:\Users\myUsername\Desktop\apache-maven-3.3.3\bin
This works just fine on my linux slaves. What is the difference? Why is this not working?
Maven changed the name of the executable in Maven 3.3 from mvn.bat to mvn.cmd. Jenkins recognized mvn.cmd since Jenkins 1.613 (see this commit). If you are on an earlier Jenkins version you can add a symlink from mvn.bat to mvn.cmd on windows as a workaround.
The executable is in the \bin folder (namely, mvn.bat). Try to point Jenkins to C:\Users\myUsername\Desktop\apache-maven-3.3.3\bin
First
Under your Windows machine
1. create an Environment Virable named MAVEN_HOME and set its value to C:\Users\myUsername\Desktop\apache-maven-3.3.3.
2. Add %MAVEN_HOME%\bin into your System PATH
Second
Go to
http://your-jenkins-server/computer/your-windows-slave/configure -->Node Properties-->Tool Locations-->(Maven)maven
and set its value to C:\Users\myUsername\Desktop\apache-maven-3.3.3 as well.
Third
Reconnect your jenkins slave, then rerun your job.
Well for me it was wrong setting for maven. Go to configure, under post build action, go to advanced setting and there fix the Maven version to be used, i changed it to maven 3.3.3 and it worked.
I am using Windows. The accepted answers does not work for me. So, I have to create a new Maven in Jenkins and select the option "Install automatically". Then it works.

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