1

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?

4

3 回答 3

2

我的理解是 %M2_HOME% 是本地 Maven 存储库的主目录,而 %MAVEN_HOME% 是 Maven 安装目录。

从记忆中,我认为 Windows 上的本地 Maven 存储库在,C:\Documents and Settings\User\.m2\但我已经使用 Linux 几年了,所以我可能错了。

检查此本地存储库文件夹并尝试将变量设置为那里。

于 2013-09-16T23:43:06.700 回答
1

我不确定为什么会这样,但确实如此。

正如 sbk 的评论所建议的,我去了构建配置。我单击“高级”以查找“使用私有 Maven 存储库”选项。

Hudson 构建 Maven 选项

我希望看到这个选项被选中,因为它可以解释问题。但事实并非如此。我没想到它会有所帮助,但无论如何我选择了该选项只是为了看看会发生什么:

使用私有 Maven 存储库

令人惊讶的是,它奏效了!我的项目再次在哈德逊建立。我仍然不知道首先是什么导致了这个问题,或者为什么这解决了它,但是既然它这样做了,这就是我的答案,除非其他人可以解释为什么它会起作用。

于 2013-09-17T15:27:20.180 回答
0

我遇到了同样的错误。早些时候我的目录被C:\apache-maven-3.0.4\apache-maven-3.0.4\bin 我重命名为文件夹结构C:\maven\apache-maven-3.0.4\bin 也相应地更新了系统变量

于 2015-03-11T10:30:34.473 回答