Can't access mvn command from command line?

2019-07-16 04:21发布

问题:

I've tried to access mvn from command line.

Installation path

C:\Program Files\Apache Software Foundation\apache-maven-3.1.1

User variables

M2 = %M2_HOME%\bin 
M2_HOME = C:\Program Files\Apache Software Foundation\apache-maven-3.1.1
JAVA_HOME = C:\Archivos de programa\Java\jdk1.7.0_25

System variables

Path = %M2%;%JAVA_HOME%/bin; and others...

I try to se if Maven is well configured through mvn --version as the manual says but this is the result:

C:\>mvn --version
"mvn" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.

C:\Program Files\Apache Software Foundation\apache-maven-3.1.1\bin>mvn --version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 17:22:22+0200)
Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.1.1
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Archivos de programa\Java\jdk1.7.0_25\jre
Default locale: es_ES, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"

What could it be this? Should I export the variables every time I need them?

回答1:

Path = %M2%;%JAVA_HOME%/bin; and others...

If you change %M2% to %M2_HOME%\bin it'll work.

To be precise: if you execute 'set Path' it must contain the path to the bin directory of Maven.



回答2:

In my past I was the same (Windows 7) and I solved it by running the cmd as administrator. Click Start - Accessories - click Command System right click Run as Administrator



回答3:

export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

mvn --version

Note: Set Java path if not available