欢迎喜欢深入了解推荐系统和mahout的兄弟加入群 推荐系统之Mahout 135918911
一直在学习mahout,工作中使用的是0.7跑算法,进行测试,但是在使用maven导入eclipse中构建的时候出现了问题,
首先由于m2e的lifeStyle覆盖问题,两个插件不能使用,如下图
m2e插件现在已经被eclipse托管,在看eclipse官方网站看过文档后终于找到解决方案,
解决方案如下:打开我们出现问题的pom文件
例如
mahout-core下的pom文件,出错的地方,表示m2e不知道怎么处理该插件(
M2E plugin execution not covered)
鼠标放到错误地方会出现
选择第二项Mark goal run as .....,如果第三项(Discover new m2e connectors)能解决最好,有的时候eclipse会出现一些connectors更新,不过很少,大多数都是使用第二种方法解决,选择后我们会看见错误提示消失
同理mahout-examples下的pom文件也这样解决如下图
同理
mahout-integration下的pom文件也这样解决如下图
同理mahout-math下的pom文件也这样解决如下图
mahout-math的pom build中插件配置是存在问题,我们最后在解决这个问题,下面继续maven问题的解决
我们如下图操作
然后
我们打开lifecycle Mapping的配置文件将全部的
<
action
>
<
ignore
/>
</
action
>
换成
<
action
>
<
execute
/>
</
action
>
或者直接将下面粘贴进去
<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId> maven-antrun-plugin</artifactId>
<versionRange>1.6</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute/>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId> maven-dependency-plugin</artifactId>
<versionRange>2.1</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute/>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.mahout</groupId>
<artifactId> mahout-collection-codegen-plugin</artifactId>
<versionRange>1.0</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId> maven-antrun-plugin</artifactId>
<versionRange>1.6</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute/>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId> maven-dependency-plugin</artifactId>
<versionRange>2.1</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute/>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.mahout</groupId>
<artifactId> mahout-collection-codegen-plugin</artifactId>
<versionRange>1.0</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
注意红色部分,默认是忽略而不是执行,需要修改成执行,或者把以上直接拷贝过去
上面的maven-antrun-plugin,
mahout-collection-codegen-plugin插件我们设置的都是执行
记得保存文件,然后在我们打开lifecycle Mapping的配置文件的配置菜单上重载红色框框下面按钮
前面说到mahout-math pom中 build配置是存在问题的,
木配置把生成的类包的存放目录添加进classpath中去
(生成路径>${project.build.directory}/generated-sources ,测试目录${project.build.directory}/generated-test-sources)
如果目录不同,请自己对应。
<configuration>
<!--<mainExcludes>-->
<!--<mainExclude>**/AbstractBooleanList.java</mainExclude>-->
<!--<mainExclude>**/BooleanArrayList.java</mainExclude>-->
<!--<mainExclude>**/BooleanBufferConsumer.java</mainExclude>-->
<!--</mainExcludes>-->
<!--<testExcludes>-->
<!--<testExclude>**/BooleanArrayListTest.java</testExclude>-->
<!--</testExcludes>-->
<outputDirectory>${project.build.directory}/generated-sources/mahout </outputDirectory>
<!--<mainExcludes>-->
<!--<mainExclude>**/AbstractBooleanList.java</mainExclude>-->
<!--<mainExclude>**/BooleanArrayList.java</mainExclude>-->
<!--<mainExclude>**/BooleanBufferConsumer.java</mainExclude>-->
<!--</mainExcludes>-->
<!--<testExcludes>-->
<!--<testExclude>**/BooleanArrayListTest.java</testExclude>-->
<!--</testExcludes>-->
<outputDirectory>${project.build.directory}/generated-sources/mahout </outputDirectory>
<testOutputDirectory>${project.build.directory}/generated-test-sources/mahout
</testOutputDirectory>
</configuration>
新增多个java文件源码包,maven本身是不支持的,我们这里需要一个插件来解决这个问题
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/mahout</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-test-sources/mahout</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/mahout</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-test-sources/mahout</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
或者我们直接粘贴0.8版本的build配置,0.8修正了这个问题,下面是0.8的配置
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-collection-codegen-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!--<mainExcludes>-->
<!--<mainExclude>**/AbstractBooleanList.java</mainExclude>-->
<!--<mainExclude>**/BooleanArrayList.java</mainExclude>-->
<!--<mainExclude>**/BooleanBufferConsumer.java</mainExclude>-->
<!--</mainExcludes>-->
<!--<testExcludes>-->
<!--<testExclude>**/BooleanArrayListTest.java</testExclude>-->
<!--</testExcludes>-->
<outputDirectory>${project.build.directory}/generated-sources/mahout</outputDirectory>
<testOutputDirectory>${project.build.directory}/generated-test-sources/mahout</testOutputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/mahout</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-test-sources/mahout</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- create test jar so other modules can reuse the math test utility classes. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<configuration>
<appendedResourcesDirectory>../src/main/appended-resources</appendedResourcesDirectory>
<resourceBundles>
<resourceBundle>org.apache:apache-jar-resource-bundle:1.4</resourceBundle>
</resourceBundles>
<supplementalModels>
<supplementalModel>supplemental-models.xml</supplementalModel>
</supplementalModels>
</configuration>
</plugin>
</plugins>
</build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-collection-codegen-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!--<mainExcludes>-->
<!--<mainExclude>**/AbstractBooleanList.java</mainExclude>-->
<!--<mainExclude>**/BooleanArrayList.java</mainExclude>-->
<!--<mainExclude>**/BooleanBufferConsumer.java</mainExclude>-->
<!--</mainExcludes>-->
<!--<testExcludes>-->
<!--<testExclude>**/BooleanArrayListTest.java</testExclude>-->
<!--</testExcludes>-->
<outputDirectory>${project.build.directory}/generated-sources/mahout</outputDirectory>
<testOutputDirectory>${project.build.directory}/generated-test-sources/mahout</testOutputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/mahout</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-test-sources/mahout</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- create test jar so other modules can reuse the math test utility classes. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<configuration>
<appendedResourcesDirectory>../src/main/appended-resources</appendedResourcesDirectory>
<resourceBundles>
<resourceBundle>org.apache:apache-jar-resource-bundle:1.4</resourceBundle>
</resourceBundles>
<supplementalModels>
<supplementalModel>supplemental-models.xml</supplementalModel>
</supplementalModels>
</configuration>
</plugin>
</plugins>
</build>
更新配置
或者我们直接把下面改好的配置替换原有build配置(下面的是0.8的配置) ,建议还是使用上面第一种
运行maven插件 clean install -Dmaven.test.skip=true -e -X
下面是apache的一个下载正式版本的依赖,对有些人可能有用
<repository>
<id>apache.releases</id>
<name>Apache Snapshot Repository</name>
<url>https://repository.apache.org/service/local/repositories/releases/content/</url>
</repository>
<id>apache.releases</id>
<name>Apache Snapshot Repository</name>
<url>https://repository.apache.org/service/local/repositories/releases/content/</url>
</repository>