要将项目代码打成war包放入测试环境,于是使用mvn clean package / mvn install 后一直报找不到本地另一个源代码目录的java类
之前对build-helper-maven-plugin插件用的很顺手,一直也没有问题,但就是不能将core这个资源目录下的java源文件打包进去,
之后就开始漫长的查找过程,比如怀疑插件版本问题,怀疑插件问题,怀疑是不是切换到jdk8后插件不支持等。
先附上插件的配置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/core</source>
<!-- 我们可以通过在这里添加多个source节点,来添加任意多个源文件夹 -->
</sources>
</configuration>
</execution>
</executions>
</plugin>
之前一直没有留意<plugins>标签外包含的<pluginmanagement>的含义,没想到和他有很大关系
pluginManagement是表示插件声明,即你在项目中的pluginManagement下声明了插件,Maven不会加载该插件,pluginManagement声明可以被继承。
查看到的链接如下:http://www.cnblogs.com/EasonJim/p/6845012.html,去掉pluginManagement标签就可以编译成功了,build的完整配置如下:
<build>
<finalName>PIMIS</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/main/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/core</source>
<!-- 我们可以通过在这里添加多个source节点,来添加任意多个源文件夹 -->
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
<webResources>
<resource>
<directory>src/main/webapp</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
<directory>target</directory>
</build>