打包带依赖包的Maven项目

<!-- 把依赖的jar包拷到lib目录下 -->

02<plugin>
03    <groupId>org.apache.maven.plugins</groupId>
04    <artifactId>maven-dependency-plugin</artifactId>
05    <executions>
06        <execution>
07            <id>copy-dependencies</id>
08            <phase>package</phase>
09            <goals>
10                <goal>copy-dependencies</goal>
11            </goals>
12            <configuration>
13                <outputDirectory>${project.build.directory}/lib</outputDirectory>
14                <overWriteReleases>false</overWriteReleases>
15                <overWriteSnapshots>false</overWriteSnapshots>
16                <overWriteIfNewer>true</overWriteIfNewer>
17            </configuration>
18        </execution>
19    </executions>
20</plugin>
21<!-- 以utf-8编码拷贝配置文件,拷贝过程中是可以做变量替换的,也就是说你的配置文件可以是个模板,里面的${}所包含的内容是可以拷贝过程中替换的 -->
22<plugin>
23    <groupId>org.apache.maven.plugins</groupId>
24    <artifactId>maven-resources-plugin</artifactId>
25    <version>2.3</version>
26    <executions>
27        <execution>
28            <id>copy-resources</id>
29            <phase>package</phase>
30            <goals>
31                <goal>copy-resources</goal>
32            </goals>
33            <configuration>
34                <encoding>UTF-8</encoding>
35                <outputDirectory>${project.build.directory}</outputDirectory><!-- 把配置文件拷到和jar包同一个路径下 -->
36                <resources>
37                    <resource>
38                        <directory>src/main/resources/</directory>
39                        <includes>
40                            <include>config.xml</include>
41                            <include>log4j.xml</include>
42                        </includes>
43                        <filtering>true</filtering>
44                    </resource>
45                </resources>
46            </configuration>
47        </execution>
48    </executions>
49</plugin>
50<!-- 打jar包时需要把配置文件给排除在外 -->
51<plugin>
52    <groupId>org.apache.maven.plugins</groupId>
53    <artifactId>maven-jar-plugin</artifactId>
54    <executions>
55        <execution>
56            <phase>package</phase>
57            <goals>
58                <goal>jar</goal>
59            </goals>
60            <configuration>
61                <classifier>lib</classifier>
62                <excludes>
63                    <exclude>config.xml</exclude>
64                    <exclude>log4j.xml</exclude>
65                </excludes>
66            </configuration>
67        </execution>
68    </executions>
69</plugin>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值