Reputation: 859
I'm trying to create a maven project with VS Code but when I run the command it says :
'mvn' is not recognized as an internal or external command,operable program or batch file.
but mvn -version
is running on command prompt
Environment varaible for User :
MAVEN_JOME : C:\apache-maven-3.6.1
,M2_HOME : C:\apache-maven-3.6.1
,JAVA_HOME : C:\Program Files\Java\jdk1.8.0_212\jre
andSystem Variables
path
is set to C:\apache-maven-3.6.1\bin
, C:\Program Files\Java\jdk1.8.0_212\bin
for maven and java respectively.
The command I'm running to create the project is:
mvn archetype:generate -DgroupId=com.cs.test-project -DartifactId=test-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
The Reference to Command
And the VS Code Reference to Command
The same command is running in Command prompt and it created the project successfully on Desktop.
Upvotes: 12
Views: 30510
Reputation: 1157
It's kinda counterintuitive as path has to be pointed to the actual mvn command, instead to a M2_PATH folder. Also once properly pointed, a new error will be shown if your environment is missing proper jdk within JAVA_HOME. The error is trown by maven. Maven plugin is kinda stupid as it will ignore your default JDK configured within settings.json (java.home or/and java.configuration.runtimes properties) and will happly NOT set java for maven. You have to configure it specificly for maven plugin as this:
"maven.executable.path": "c:\\apache-maven-3.8.1\\bin\\mvn",
"maven.terminal.customEnv": [{
"environmentVariable": "JAVA_HOME",
"value": "c:\\openjdk-1.8.0_232-redhat",
}]
Of course, both paths should be pointed to proper folders/files in your environment.
Upvotes: 5
Reputation: 607
I am using Ubuntu 20.0.
In my case, I added the path to the Maven binary directory manually to the $PATH
variable. I accidentally only added it to the environment variables in the shell but not to the user session.
Also make sure you are using the official binary that you can download from Maven's website and not the Ubuntu APT package because that one is too old and did not work for me.
Let's assume, the Maven executable has been stored in ~/apache-maven/bin
. Then you can edit ~/.profile
by adding export PATH+=":$HOME/apache-maven/bin"
.
Restart the computer and then, when you login to your profile, mvn
should be visible by programs as well as VSCode.
Upvotes: 0
Reputation: 101
On Tuesday Oct. 25, 2022 while trying to solve the same problem, I went through all of these previous solutions for Windows and finally had to resort to the official installation docs:
Unzipped the download and located the bin directory and manually added that directory location to my: System Properties>Advanced>Environment Variables>'Path'
For good measure, restart the computer.
Upvotes: 2
Reputation: 1
The way I fixed was by changing the exec path in Vs Code settings from CMD to Powershell.
Open
settings -> features -> terminal
Change the windows exec
path from cmd to where you have PowerShell.
For example: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Upvotes: 0
Reputation: 384
I fixed this problem by simply restarting VSCode as I had set my PATH variable while my VSCode was running so the changes were not reflected to the VSCode integrated terminal until I restarted it.
Upvotes: 7