Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Mvn (Maven) not recognized as command

  1. #1
    Junior Member
    Join Date
    Aug 2022
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Mvn (Maven) not recognized as command

    Sorry, I don’t know what the appropriate forum for this question is.

    I am following a course Maven Fundamentals on Pluralsight.

    I installed Spring Tools Suite 4 and Maven.
    Maven I installed on the G drive and I assumed that is why it didn’t work.

    In the command prompt instructing
    mvn –version
    yields
    'mvn' is not recognized as an internal or external command, operable program or batch file.

    However, I tried putting it in a few places on the C drive, but that didn’t help.

    There is however a difference that puzzles me. I am talking about the setting found at (translated from Dutch)
    System Variables → Environment Variables → in table System Variables select ‘Path’ → Edit…

    The first time I did that I got a table with lines and I could add the line %MAVEN_HOME%bin
    Now eacht time I go there the table is compacted in a single line, like this :
    %JAVA_HOME%\bin;%MAVEN_HOME%\bin%;TRICENTIS_SEARCH %;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\ System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerSh ell\v1.0\;%SYSTEMROOT%\System32\OpenSSH\;C:\Progra m Files\Java\jdk-18.0.2.1\bin;C:\Program Files (x86)\dotnet\;C:\Program Files\dotnet\;

    How can I explain to the command prompt where to find the mvn command ?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,892
    Thanks
    58
    Thanked 2,692 Times in 2,642 Posts

    Default Re: Mvn (Maven) not recognized as command

    The OS needs a way to find any command that is entered on the command line.
    One way is to give the full path to the command on the command line. For example:
    D:\Program Files\Java\jdk1.8.0_60\bin\javac.exe -cp .;D:\JavaDevelopment -Xlint -Xdiags:verbose TestCode27.java

    Another way is to enter the path to the command to the PATH environment variable.

    What is in your PATH variable? Open a command prompt and enter PATH - that will display PATH's contents.
    What is in the MAVEN_HOME variable?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2022
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Mvn (Maven) not recognized as command

    Thanks for your response.

    Now Maven is in
    C:\Dev\apache-maven-3.8.6

    It does not contain an .exe file, so I don’t know how to run it.

    The System variable MAVEN_HOME is
    C:\Program Files\Dev\apache-maven-3.8.6

    That is wrong. I forgot to update when moving Maven around. I change it to
    C:\Dev\apache-maven-3.8.6

    Adding \bin to that doesn’t help.

    I don’t know the PATH variable.

    The Maven readme says :
    “set PATH="c:\program files\apache-maven-3.x.y\bin";%PATH%”

    I don’t know what the %PATH% at the end means. I suspect it means adding c:\ etcetera to in front of what is already there.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,892
    Thanks
    58
    Thanked 2,692 Times in 2,642 Posts

    Default Re: Mvn (Maven) not recognized as command

    Now Maven is in
    C:\Dev\apache-maven-3.8.6
    Given that location, the PATH variable should contain this with all the other values currently in PATH:
    C:\Dev\apache-maven-3.8.6\bin

    I think MAVEN_HOME should be set to:
    C:\Dev\apache-maven-3.8.6

    I don’t know the PATH variable.
    Ask Google how to add a value to PATH for Windows.

    --- Update ---

    For example:
    https://www.architectryan.com/2018/0...on-windows-10/
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    Amoranemix (September 4th, 2022)

  6. #5
    Junior Member
    Join Date
    Aug 2022
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Mvn (Maven) not recognized as command

    I again set MAVEN_HOME to C:\Dev\apache-maven-3.8.6

    I ask google how to add a value to the PATH for Windows.
    There is no PATH variable.
    There is a Path variable (see OP; I have removed the last % from %MAVEN_HOME%\bin%), but I don’t know what I am supposed to fill in there and I don’t get the fancy table.
    So I create a PATH variable, that I set to value %MAVEN_HOME%\bin.

    I instruct
    mvn --version

    Something extraordinary happened. It worked!
    Maven home: C:\Dev\apache-maven-3.8.6
    Java version: 18.0.2.1, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-18.0.2.1
    Default locale: nl_BE, platform encoding: UTF-8
    OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
    'cmd' is not recognized as an internal or external command,
    operable program or batch file.

    In Environment Variables, the Path variable has vanished! (I new there had to be a catch.) Java still works for some reason, but I suspect I’ll run into trouble later.
    How can Java work without its path being in the PATH variable ?

    I set the PATH variable to be
    %JAVA_HOME%\bin;%MAVEN_HOME%\bin;TRICENTIS_SEARCH% ;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\S ystem32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShe ll\v1.0\;%SYSTEMROOT%\System32\OpenSSH\;C:\Program Files\Java\jdk-18.0.2.1\bin;C:\Program Files (x86)\dotnet\;C:\Program Files\dotnet\;

    mvn –version still works

    I remove C:\Program Files\Java\jdk-18.0.2.1\bin from the PATH variable (as it seems a double of %JAVA_HOME%\bin).

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,892
    Thanks
    58
    Thanked 2,692 Times in 2,642 Posts

    Default Re: Mvn (Maven) not recognized as command

    Have you solved the problem now?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #7
    Junior Member
    Join Date
    Aug 2022
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Mvn (Maven) not recognized as command

    Yes, but I still don’t understand why Java worked without the path having been indicated in the PATH variable.

    Further, I keep following along with the instructions of the Pluralsight course ‘Maven Fundamentals’.

    Program : Spring Tool Suite 4
    Directory : C:\Users\Knarf\Documents\School\Informatica\Worksp aces\Spring Tool Suite workspace
    In there is a project is created with folders \HelloWorld\src\main\java

    In HelloWorld : .project and pom.xml
    In java : HelloWorld.java

    pom.xml :
    <project>
    	<groupId>com.pluralsight</groupId>
    	<artifactId>HelloWorld</artifactId>
    	<version>1.0-SNAPSHOT</version>
    	<model>4.0.0</model>
    	<packaging>jar</packaging>
    </project>

    HelloWorld.java :
    public class HelloWorld {
    	public static void main(String[] args) {
    		system.out.println("Hello world!") ;
    	}	
    }

    The teacher says to run mvn clean and then good stuff would happen.

    When I instruct
    mvn clean
    I get
    [INFO] Scanning for projects...
    [ERROR] [ERROR] Some problems were encountered while processing the POMs:
    [ERROR] Malformed POM C:\Users\Knarf\Documents\School\Informatica\Worksp aces\Spring Tool Suite workspace\HelloWorld\pom.xml: Unrecognised tag: 'model' (position: START_TAG seen ...</version>\r\n\t<model>... @5:9) @ C:\Users\Knarf\Documents\School\Informatica\Worksp aces\Spring Tool Suite workspace\HelloWorld\pom.xml, line 5, column 9
    [ERROR] 'modelVersion' is missing. @ line 1, column 9
    [ERROR] 'modelVersion' is missing. @ line 1, column 9
    <etcetera>

    In STS 4, in the pom file there is a red x at line one and a underlining of the closing bracket as if something extra is needed between project and >. Hovering over the red x says :
    “Multiple annotations found at this line :
    - No grammar constraints (DTD or XML Schema).
    - ‘modelVersion’ is missing.”

    At line 5 (<model>4.0.0</model>) there is a warning that looks the same as the ‘ Malformed POM C:\Users\K‘ error line (the 3rd) in the command prompt.

    I found suggestions online about replacing <project> with
    <?xml version="1.0" encoding="UTF-8"?>
    <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">

    but that doesn’t improve matters.

    How can I get the clean command to do good stuff with that project ?

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,892
    Thanks
    58
    Thanked 2,692 Times in 2,642 Posts

    Default Re: Mvn (Maven) not recognized as command

    Sorry, I do not know how to use Maven.

    Java worked without the path having been indicated in the PATH variable.
    The program provided the full path to the java.exe command so that the OS could find it.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #9
    Junior Member
    Join Date
    Aug 2022
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Mvn (Maven) not recognized as command

    Is there on this forum a good place to ask about Maven and if so, where ?

    Quote Originally Posted by Norm View Post
    The program provided the full path to the java.exe command so that the OS could find it.
    What program provided that path ?

  11. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,892
    Thanks
    58
    Thanked 2,692 Times in 2,642 Posts

    Default Re: Mvn (Maven) not recognized as command

    What program was executing when
    Java worked without the path having been indicated in the PATH variable.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #11
    Junior Member
    Join Date
    Aug 2022
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Mvn (Maven) not recognized as command

    The Command prompt was executing when commands starting with java worked.

  13. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,892
    Thanks
    58
    Thanked 2,692 Times in 2,642 Posts

    Default Re: Mvn (Maven) not recognized as command

    The OS needs a path to find any program that it executes.
    Either the full path to the program is provided or the program is in the current directory
    or the path to the program is in the Path environment variable.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #13
    Junior Member
    Join Date
    Aug 2022
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Mvn (Maven) not recognized as command

    I am in C:\Users\Knarf>

    I removed %JAVA_HOME%\bin from the PATH variable.
    Yet the command java --version still works.

    I also removed %MAVEN_HOME%\bin from the PATH variable.
    The command mvn --version still works.

    I put them both back and give the variable JAVA_HOME and MAVEN_HOME a wrong value.
    Yet both commands still work.

    When I restart the Command Prompt, neither work.
    So, I correct them.
    Neither still work.
    So, I restart the Command Prompt.
    Problem solved.

    Next, I remove %JAVA_HOME%\bin from PATH and restart the Command Prompt.
    Java –version doesn’t work anymore;

    That probably explains why I had trouble with the mvn command before. I had to restart the Command Prompt before changes to the path would take effect.

  15. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,892
    Thanks
    58
    Thanked 2,692 Times in 2,642 Posts

    Default Re: Mvn (Maven) not recognized as command

    restart the Command Prompt before changes to the path would take effect.
    Yes, that is true.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] JButton not being recognized
    By AstralBoat in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 31st, 2019, 05:59 PM
  2. why the command prompt does not recognize java as a command?
    By bihlas in forum Java Theory & Questions
    Replies: 1
    Last Post: July 22nd, 2014, 09:50 AM
  3. [SOLVED] Javac Not recognized?
    By Future_Programmer in forum Java Theory & Questions
    Replies: 4
    Last Post: June 12th, 2013, 06:04 AM
  4. Replies: 1
    Last Post: September 9th, 2012, 09:36 PM
  5. IP Can't Recognized
    By Voipswitch1 in forum Java Networking
    Replies: 1
    Last Post: February 8th, 2012, 06:03 PM