maven编译后复制到目标位置
原创
©著作权归作者所有:来自51CTO博客作者仓储大叔的原创作品,请联系作者获取转载授权,否则将追究法律责任
maven对项目进行打包之后,可以将打包好的jar和某些资源文件复制到指定位置,例如你的项目结构是services父项目下有个子项目,service-1,它在打包之后,希望把jar和templates文件夹复制到父项目services的target目录,这就可以使用maven的两个插件来完成。
maven-dependency-plugin
编译之后,将当前项目的jar复制到某个目录下
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</artifactItem>
</artifactItems>
<outputDirectory>../target</outputDirectory>
<stripClassifier>true</stripClassifier>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
maven-resources-plugin
将资源目录resources下的某些文件,复制到上一级目录的templates下
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>../target/templates</outputDirectory>
<resources>
<resource>
<directory>${basedir}/templates</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
这两个插件在多级项目中,使用的很多,比如,你的多层项目都是一个SPI,这些SPI放在一起打一下镜像,对外提供服务,你就可以使用这两个插件来将它们的jar输出到父目录下。
作者:仓储大叔,张占岭,
荣誉:微软MVP