Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

M2_HOME environment variable not set? #14

Open
mmoayyed opened this issue Apr 17, 2016 · 6 comments
Open

M2_HOME environment variable not set? #14

mmoayyed opened this issue Apr 17, 2016 · 6 comments

Comments

@mmoayyed
Copy link

> .\mvnw.bat clean

ERROR: M2_HOME is set to an invalid directory.
M2_HOME = "c:\person-directory\.."
Please set the M2_HOME variable in your environment to match the
location of the Maven installation

Using:

            <plugin>
                <groupId>com.rimerosolutions.maven.plugins</groupId>
                <artifactId>wrapper-maven-plugin</artifactId>
                <version>0.0.1</version>
            </plugin>
@mmoayyed
Copy link
Author

Upgraded to:

          <plugin>
                <groupId>com.rimerosolutions.maven.plugins</groupId>
                <artifactId>wrapper-maven-plugin</artifactId>
                <version>0.0.4</version>
            </plugin>

No difference.

@yveszoundi
Copy link
Member

Thanks I'll take a look soon.

@yveszoundi
Copy link
Member

Disclaimer: I still don't have any MS Windows virtual machines, so I don't really test under Windows

Please try again with the snapshot version 0.0.5-SNAPSHOT.
You can use the Maven wrapper example project for the repository configuration.
Alternatively, you can wait until 0.0.5 is propagated to Maven Central (about 3 days or so).

If you still encounter issues, please provide comprehensible details about what you're doing and what is failing. Ensure that you update the wrapper jar via mvn wrapper:wrapper first.

Regards,
Yves

@chuckwondo
Copy link

The problem is that the generated mvnw.bat file attempts to set M2_HOME and then make sure that %M2_HOME%\bin\mvn.cmd exists. However, since the whole purpose of this wrapper is to avoid the need for someone to have Maven already installed, this really seems to make no sense. That is, Maven does not have to be installed already, thus M2_HOME should not need to be set.

To confirm, using version 0.0.4, the generated mvnw.bat file contains the following line (line 100):

if exist "%M2_HOME%\bin\mvn.cmd" goto init

Since I don't already have M2_HOME defined, the script sets it to the parent directory of the directory where mvnw.bat files exists. Therefore, goto init does not happen because the existence check fails, leading to the script failure with the error message noted earlier.

However, as I mentioned, there should be no need for such an existence check, so I changed the line above (line 100) to the following:

goto init

After doing so, mvnw.bat works perfectly well.

This makes sense since M2_HOME is never actually used in the script (after line 100, other than using it's value in the subsequent error message). My guess is that everything related to M2_HOME can be completely removed because it's probably some sort of remnant of some very old logic that is now obsolete.

Although the mvnw script does not have the same problem, because it doesn't actually do any sort of existence check, I imagine that it should also have all code dealing with M2_HOME removed, as it is likely obsolete as well.

I'm happy to fork, fix, test, and submit a PR, if this makes sense.

@yveszoundi
Copy link
Member

Hello @chuckwondo, sorry for the late response, I don't have much time lately outside of work.

I'd gladly accept a PR for it, I'm not a Windows user myself so Windows scripts are usually only improved/developed when I'm abroad visiting relatives (no thorough testing).

@chuckwondo
Copy link

@yveszoundi No apology necessary. I'm glad to help. I use Windows and OS X, so I'm happy to help with the Windows side of things. I've also run into this issue, so I finally took the time to dig into it to find the source of the problem.

Regarding the mvnw and mvnw.bat files that are part of this repository itself, how were they generated? I want to update them as well, but since this project's pom.xml does not reference (an earlier version of) itself, it's not obvious to me how the wrapper scripts and the contents of the maven directory were generated.

I will manually update the mvnw and mvnw.bat files, if that's appropriate, but if that's not appropriate, please provide instructions for regenerating them.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants