带依赖包的maven打包配置
转载自:http://outofmemory.cn/code-snippet/2594/carry-yilai-bao-maven-dabao-configuration
可以在maven的package生命周期内使用copy-dependencies复制依赖包,如下pom.xml文件内容:
<!-- 把依赖的jar包拷到lib目录下 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> <!-- 以utf-8编码拷贝配置文件,拷贝过程中是可以做变量替换的,也就是说你的配置文件可以是个模板,里面的${}所包含的内容是可以拷贝过程中替换的 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>copy-resources</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <outputDirectory>${project.build.directory}</outputDirectory><!-- 把配置文件拷到和jar包同一个路径下 --> <resources> <resource> <directory>src/main/resources/</directory> <includes> <include>config.xml</include> <include>log4j.xml</include> </includes> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> <!-- 打jar包时需要把配置文件给排除在外 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>jar</goal> </goals> <configuration> <classifier>lib</classifier> <excludes> <exclude>config.xml</exclude> <exclude>log4j.xml</exclude> </excludes> </configuration> </execution> </executions> </plugin>