Hudson ERROR: M2_HOME is set to an invalid directory

匿名 (未验证) 提交于 2019-12-03 09:10:12

问题:

I am using a computer with Windows 7, and I have Hudson installed on it. I have had this installation for a while, and it has been working fine up till now.

Something has changed. Now, whenever I try to build a project, after successfully checking out the project from SVN, it fails with this message:

ERROR: M2_HOME is set to an invalid directory. M2_HOME = "C:\Build\Hudson\.hudson\jobs\Score_Plugin\workspace\.." Please set the M2_HOME variable in your environment to match the location of the Maven installation

I cannot figure out why it is giving me this error. Why is Hudson trying to find M2_HOME in its own workspace? I tried the following, which seems to say that my Maven installation in my environment is just fine:

1. I opened up a CMD and typed in `where mvn` and got the following:

C:\Build\Maven\apache-maven-3.0.5\bin\mvn C:\Build\Maven\apache-maven-3.0.5\bin\mvn

2. I typed in `mvn -version` and got this:

Apache Maven 3.0.5 <r01de14724cdef164cd33c7c82fe155faf9602da; 2013-02-19 05:51:28-0800> Maven home: C:\Build\Maven\apache-maven-3.0.5 Java version: 1.7.0_25, vendor: Oracle Corporation Java home: C:\Build\Java\jdk1.7.0_25_x64\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

3. I checked to see, and I have a `MAVEN_HOME` environment variable set to `C:\Build\Maven\apache-maven-3.0.5`.
I also have `%MAVEN_HOME%\bin` in my path.

It looks like my environment is working.

4. In an attempt to solve this error, I created a M2_HOME environment variable and set it equal to %MAVEN_HOME%.

5. To top it all off, I've rebooted my machine.

I'm still getting this error. I'm getting it for every project I try to build in Hudson. I'm not sure what I else I can do. Any ideas?

回答1:

My understanding is that %M2_HOME% is the home of the local Maven repository as opposed to %MAVEN_HOME% which is the Maven installation directory.

From memory, I think the local Maven repository on Windows is in C:\Documents and Settings\User\.m2\ but I've been Linux through-and-through for a few years now so I may be wrong.

Check for this local repository folder and try setting the variable to there instead.



回答2:

I am not sure why this worked, but it did.

As suggested by sbk's comment, I went to the build configuration. I clicked "advanced" to look for the `Use private Maven repository` option.

I expected to see this option selected as it would explain the problem. But it wasn't. I didn't expect it would help, but I selected the option anyway just to see what would happen:

Amazingly, it worked! My project builds again in Hudson. I still don't know what caused this problem in the first place, or why this fixed it, but since it did this is the answer for me unless someone else can explain why this worked.



回答3:

I was getting same error. Earlier my directory was C:\apache-maven-3.0.4\apache-maven-3.0.4\bin I renamed the folder structure as C:\maven\apache-maven-3.0.4\bin Also updated the system variable accordingly



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!