随笔-95  评论-31  文章-10  trackbacks-0
第一种:可执行jar与依赖分开,依赖在lib目录里,需要jar和lib目录在同级目录,
优点:jar文件很小 
缺点:需要放置lib文件夹在平级目录

 1            <plugin>
 2                <groupId>org.apache.maven.plugins</groupId>
 3                <artifactId>maven-jar-plugin</artifactId>
 4                <version>2.6</version>
 5                <configuration>
 6                    <archive>
 7                        <manifest>
 8                            <addClasspath>true</addClasspath>
 9                            <classpathPrefix>lib/</classpathPrefix>
10                            <mainClass>com.xxx.xxxService</mainClass>
11                        </manifest>
12                    </archive>
13                </configuration>
14            </plugin>
15            <plugin>
16                <groupId>org.apache.maven.plugins</groupId>
17                <artifactId>maven-dependency-plugin</artifactId>
18                <version>2.10</version>
19                <executions>
20                    <execution>
21                        <id>copy-dependencies</id>
22                        <phase>package</phase>
23                        <goals>
24                            <goal>copy-dependencies</goal>
25                        </goals>
26                        <configuration>
27                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
28                        </configuration>
29                    </execution>
30                </executions>
31            </plugin>

第二种:把所有依赖打进同一个jar包里。
缺点:jar文件会比较大,同时该插件有个bug会缺失spring的xds文件,导致无法运行jar,同时如果同级目录还有其它可执行jar文件依赖可能会产生冲突
优点:方便快捷,打包完直接就能运行。

 1            <plugin>
 2                <artifactId>maven-assembly-plugin</artifactId>
 3                <configuration>
 4                    <descriptorRefs>
 5                        <descriptorRef>jar-with-dependencies</descriptorRef>
 6                    </descriptorRefs>
 7                    <archive>
 8                        <manifest>
 9                            <mainClass>com.xxx.xxxService</mainClass>
10                        </manifest>
11                    </archive>
12                </configuration>
13                <executions>
14                    <execution>
15                        <id>make-assembly</id>
16                        <phase>package</phase>
17                        <goals>
18                            <goal>single</goal>
19                        </goals>
20                    </execution>
21                </executions>
22            </plugin>

第三种:所有依赖打到同一个jar文件里。
缺点:jar文件过大、如果同级目录有其它可执行jar,依赖可能会产生冲突
优点:不会有任何bug,直接打成可执行jar文件,最省事。

 1            <plugin>
 2                <groupId>org.apache.maven.plugins</groupId>
 3                <artifactId>maven-shade-plugin</artifactId>
 4                <version>2.4.3</version>
 5                <executions>
 6                    <execution>
 7                        <phase>package</phase>
 8                        <goals>
 9                            <goal>shade</goal>
10                        </goals>
11                        <configuration>
12                            <filters>
13                                <filter>
14                                    <artifact>*:*</artifact>
15                                    <excludes>
16                                        <exclude>META-INF/*.SF</exclude>
17                                        <exclude>META-INF/*.DSA</exclude>
18                                        <exclude>META-INF/*.RSA</exclude>
19                                    </excludes>
20                                </filter>
21                            </filters>
22                            <transformers>
23                                <transformer
24                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
25                                    <resource>META-INF/spring.handlers</resource>
26                                </transformer>
27                                <transformer
28                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
29                                    <resource>META-INF/spring.schemas</resource>
30                                </transformer>
31                                <transformer
32                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
33                                    <resource>META-INF/spring.tooling</resource>
34                                </transformer>
35                                <transformer
36                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
37                                    <mainClass>com.xxx.xxxInvoke</mainClass>
38                                </transformer>
39                            </transformers>
40                            <minimizeJar>true</minimizeJar>
41                            <shadedArtifactAttached>true</shadedArtifactAttached>
42                        </configuration>
43                    </execution>
44                </executions>
45            </plugin>















posted on 2017-05-03 10:08 朔望魔刃 阅读(15118) 评论(0)  编辑  收藏 所属分类: java

只有注册用户登录后才能发表评论。


网站导航: