关于maven 项目install报错的问题以及解决办法

  • 问题

近日有很多童鞋反映,javashop 6.1及6.0版本执行mvn install时报错,报错信息大致如下:

经过测试发现,在eclipse环境下运行mvn install正常,而shell下使用指令mvn install则会报错;分析后发现是因为eclipse环境能够识别我们的java resourse,而shell或者命令行下无法识别我们的java resource。

  • 标准的maven项目的目录结构是:src/main/java  
  • 标准的maven项目的test目录结构是:src/test/java
  • 标准的maven项目的配置文件路径是:src/main/resources

当我们不使用这种标准的maven项目结构时,在shell下 执行mvn install 就会发生找不到类或者找不到资源的问题。

  • 解决办法
  • 引入build-helper-maven-plugin插件

    <!– 增加更多的Source和Test Source目录插件 –>
    <plugin>
         <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.12</version>
    </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>src/eop</source>
<source>src/base</source>
</sources>
</configuration>
</execution>

<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/base</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.html</include>
<include>**/*.css</include>
</includes>
</resource>
<resource>
<directory>src/eop</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.html</include>
<include>**/*.css</include>
</includes>
</resource>
</resources>
</configuration>
</execution>

</executions>

</plugin>

  • 配置eclipse lifecycle-mapping

<pluginManagement>
<plugins>
<!–This plugin’s configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. –>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
build-helper-maven-plugin
</artifactId>
<versionRange>
[1.12,)
</versionRange>
<goals>
<goal>add-source</goal>
<goal>add-resource</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>

配置完成之后再试试,看看是不是问题已经解决了?

如果您购买了javashop 的61版,我们已经更新了pom.xml文件哦,只需要更新pom文件即可。

  • 另外在mvn install b2b2c 之前  需要先mvn install javashop

发表评论