Maven runs on Netbeans just fine. I'm trying to figure out why it doesn't like IntelliJ. I've done some Googling and can't figure out what's wrong. I've read things about specifying a path in my environmental variables, but I have no idea what my "maven install path" is.
I have followed these instructions which are listed on Maven's Download Page...
Windows 2000/XP
Unzip the distribution archive, i.e. apache-maven-3.0.4-bin.zip to the directory you wish to install Maven 3.0.4. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.0.4 will be created from the archive.
Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.0.4. Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven 2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.
In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.
Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.
In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.
In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.
Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.
Turns out I had downloaded the source, not the binary. Once I downloaded the binary it worked fine.
Related
Is there a way to tell SBT which (locally) installed JDK to use?
I am quite certain I could change PATH and JAVA_HOME but I'd rather not change those settings since they apply for the whole system (Windows in that case).
I am more looking for a command line parameter of some sort.
If you're looking to specify a JDK for running SBT (rather than a JDK to use for running your code and/or tests from within SBT), you can make use of the JAVA_HOMES environment variable, plus a .java-version file in your project.
This is described in SBT's sbt.bat file (typically installed to C:\Program Files (x86)\sbt\bin) as a "poor man's jenv", which isn't currently available on Windows.
(If you're looking for a similar solution for Linux or MacOS, you can either use jEnv, or specify the Java home directory via the -java-home SBT command line option—which also, sadly, isn't currently implemented on Windows.)
The JAVA_HOMES environment variable (not to be confused with JAVA_HOME) is used by SBT to identify a directory that contains one or more JDK installations. For example, if you're using AdoptOpenJDK's JDK distributions (recommended on Windows, if Oracle's new licensing restrictions are a problem for you), then this would typically be defined as C:\Program Files\AdoptOpenJDK.
Let's say that you have two such JDK installations in the JAVA_HOMES directory: one in a subdirectory named jdk-8.0.212.03-hotspot; another in the jdk-11.0.3.7-hotspot subdirectory. You can select which JDK you want to use, on a project-by-project basis, by creating a file called .java-version in the root directory of each SBT project. To use the JDK in the jdk-8.0.212.03-hotspot subdirectory, this file should then contain:
jdk-8.0.212.03-hotspot
When you run the sbt command, if you have JAVA_HOMES defined, SBT will look for a .java-version file in the project's root directory. If it finds it, it creates a local version of JAVA_HOME that is defined as JAVA_HOMES plus the last line of .java-version. It also adds this JAVA_HOME's bin directory to the path. (It also creates a JDK_HOME process-local environment variable with the same value.)
This should do what you want. Although it's not a command line-based solution, it doesn't adversely affect other users, and allows each SBT project to be configured individually. If you do not have permission to create a system-wide environment variable, you should still be able to create a user-specific JAVA_HOMES environment variable. Note that when using this solution, the JDK that SBT uses is then not necessarily the one identified by your system-wide (or user-specific) JAVA_HOME environment variable. (If you have not defined JAVA_HOMES, then SBT will expect you to have defined a valid JAVA_HOME variable.)
One word of caution: if you commit .java-version to source control, you must ensure that everyone defines a valid JAVA_HOMES environment variable, and has a JDK with the exact same name installed in that directory.
I am trying to install maven v3.5.4 onto my computer and whenever I try the 'mvn -version' command, I get
'mvn' is not recognized as an internal or external command,
operable program or batch file.
I have looked up multiple tutorials on how to do this, and they are giving nearly the same information. Add system variables M2 and M2_HOME, then append a directory to the Path system variable. I have the System Variables configured to the following:
M2:
Name: M2
Value: C:\Program Files\Apache\maven\bin
M2_HOME:
Name: M2_HOME
Value: C:\Program Files\Apache\maven
MAVEN_HOME:
Name: MAVEN_HOME
Value: C:\Program Files\Apache\maven
Path:
Name: Path
Value: %M2_HOME%\bin;%JAVA_HOME%\bin
I have seen people saying that there should be a .exe or .bat file inside the bin directory. I do not have any of these. I only have 4 files inside this folder.
This could perhaps be the issue. The path to my Maven directory is:
I have the following maven related system variables:
And my Path variable is:
I'm not sure how to fix this issue so if anyone knows, please let me know.
Add a variable MAVEN_HOME like:
Name: MAVEN_HOME
Value: C:\Program Files\apache-maven-3.3.9\bin
In your case, the M2_HOME path is not correct. Hence It must not be working. Try to give the correct path to the bin folder.
First you have to download maven from here, preferably the latest version and install it.
Then, you have to set the Path variable for Maven.
Go to Start and search for 'Edit the system environment variables'.
Choose the environment variables option and like you do in the example you provided, leave M2_HOME as you have it, delete M2 and change the one in your path to: %M2_HOME%\bin\;
Also, please make sure that you are editing the system environment variables.
As I it says on the download page of the version you are trying to install: "Maven 3.3+ require JDK 1.7 or above to execute". So make sure you have the right version of java.
If this does not work, then I don't think someone on Stack-Overflow can help.
Install Java
Download Java SE Development Kit from Oracle's website and install it
Browse via windows search to Environment Variables
Press New... in System variables list
Insert JAVA_HOME to Variable name
Insert its path to Variable value (e.g: C:\Program Files\Java\jdk1.8.0_102)
Press Edit to Path and then press New
Insert %JAVA_HOME%\bin
Open cmd and type java -version to check if it is ok
Install Maven
Download Maven Binary zip archive from Apaches's website
Unzip the folder and move it to C:\Program Files
Browse via windows search to Environment Variables
Press New... in System variables list
Insert MAVEN_HOME to Variable name
Insert its path to Variable value (e.g: C:\Program Files\apache-maven-3.6.2)
Press Edit to Path and then press New
Insert %MAVEN_HOME%\bin
Open cmd and type mvn -version to check if it is ok
I have downloaded the maven 3.5.0 from here. I have set it in the path:
C:\apache-maven-3.5.0
Then i treid to add it to the path of Windows 7 as below:
Right click on my computer
Properties
Advanced System Setting
Environment Variable
New user variable and added Maven_Home with value C:\apache-maven-3.5.0
Add it to path variable with: %Maven_Home%\bin
Open cmd and ask for mvn -version in desktop
Result:
It does not recognize maven
In windows:
Download the latest version of Maven from the http://maven.apache.org/ and Navigate to Use --> Download --> Download the Binary zip archive.
1) After the download, unzip the folder and copy it to the folder. (Lets say i have copied to c:\program files\apache-maven-3.52.
2) Setting the path of Maven in environment Variables:
Search the Environment Variable --> Edit the System Environment variables--> Navigate to Advanced tab --> Environment Variables
i) MAVEN_HOME : Click New --> Variable Name : MAVEN_HOME , Variable Value: C:\Program Files\apache-maven-3.5.2
ii) M2_HOME : Click New --> Variable Name : M2_HOME , Variable Value: C:\Program Files\apache-maven-3.5.2
iii) Edit the 'Path' Environment Variable --> %M2_HOME%\bin
Testing whether Maven is installed:
mvn -version
References:-
http://www.baeldung.com/install-maven-on-windows-linux-mac
NOTE : In point iii don't forget to put semicolon(;) before and after.
Open command console
copy this
set PATH="c:\program files\apache-maven-3.x.y\bin";%PATH%
cahnge the path accordingly
click enter
it's all set and now check mvn -version
I had the same problem and fixed the issue by:
Adding the M2_HOME to the USER VARIABLES
Adding the MAVEN_HOME to the USER VARIABLES
Adding the BIN folder to the PATH in the SYSTEM VARIABLES
(conform this video: https://www.youtube.com/watch?v=RfCWg5ay5B0)
Then i could run mvn -version in a NEW command terminal.
The problem get solved when i edit the path variable with ;%Maven_Home%\bin; so i should add the ; before and after it.
Adding
MAVEN_HOME variable (C:\Program Files\apache-maven-3.5.2) and M2_HOME variable (C:\Program Files\apache-maven-3.5.2\bin).
Add %MAVEN_HOME%\bin to the path in system variables .
Then mvn -version in command prompt.
Make sure you download the Binary zip file from https://maven.apache.org/download.cgi. Then it should work fine by adding it to the path variable as mentioned in other answers. I've accidentally downloaded the src.zip file and of course it didn't work.
Additionally I would add this information that worked for me
After I opened the Environment Variables and followed these steps:
System variables > path > edit > add this one: C:\apache-maven-3.6.3\bin > ok button.
Also I would send my System variables you may need
I am using Windows 10
The changes in "System variables" requires system restart to take effect. ( The same for Linux systems also)
After doing changes, you need to reopen CMD window. In my case, my terminal window was opened before updating environment variables, and changes were not reflecting there i.e. mvn -version was returning "...not recognized as an internal or external command".
1) Make sure JDK is installed, and “JAVA_HOME” variable is added as Windows environment variable.
1) Download the Maven zip file, for example : apache-maven-3.5.0-bin.zip. Unzip it to the folder you want to install Maven.
Assume you unzip to this folder – C:\Program Files\Apache\maven
3) Set the environment variables using system properties. Add M2_HOME, M2, MAVEN_OPTS to environment variables.
M2_HOME=C:\Program Files\Apache\maven\apache-maven-3.5.0
M2=%M2_HOME%\bin
MAVEN_OPTS=-Xms256m -Xmx512m
4) Now append M2 variable to System Path.
Append the string ;%M2% to the end of the system variable, Path.
5) Open Command Console and run this command c:\> mvn --version
you will get bellow output :
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T17:27:37+05:30)
Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.3.3
Java version: 1.7.0_75, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_75\jre
Default locale: en_US, platform encoding: Cp1252
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
There seems to be a problem with the system properties in Maven. It seems that system properties don't correspond to the environment variables.
The situation is that I would like to the change the absolute location of the user-specific settings.xml file, as the Maven document says
If you need to create user-specific settings from scratch, it’s
easiest to copy the global settings from your Maven installation to
your ${user.home}/.m2 directory
which means that the only way to change the absolute location of the user-specific file is to change the user.home property. But it seems that this is not exactly the HOME or HOMEPATH environment variable. In fact, I deleted all the environment variables such as HOME and HOMEPATH, and run mvn using mvn -X just to see the user-specific settings.xml that mvn uses. The result is the following (I am in Windows 7 and I run the command in cmd.exe):
Maven still finds a user.home property, however, I haven't set such a environment variable. To verify this, I then run the set command to see all the environment variables but find nothing about the path d:\Userfiles\xili\ which is used by Maven as the user.home system property. By the way, there is no settings.xml file in this path, because I haven't put any file in this path.
How maven figure out such a path as user.home?
The answer is here!
http://www.timehat.com/javas-user-home-is-wrong-on-windows/
In fact, in Windows, the JVM uses the PATH_TO_DESKTOP_FOLDER_AS_SET_IN_THE_REGISTRY as the reference to determine wheres is the user.home.
user.home is just the parent folder of the above path. That't it, this has nothing to do with the HOME or HOMEPATH enviroment variable.
In the source code of Maven, there should be some code like System.getProperty('user.home').