码迷,mamicode.com
首页 > 编程语言 > 详细

IDEA结合maven将依赖都打入jar包

时间:2020-01-08 17:29:39      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:blog   pad   build   hot   col   artifact   assembly   resource   tool   

1、在pom.xml中添加插件

<build>
    <plugins>
        <plugin>
            <groupId>org.scala-tools</groupId>
            <artifactId>maven-scala-plugin</artifactId>
            <version>2.15.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass></mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <defaultGoal>compile</defaultGoal>
</build>

<mainClass></mainClass> 中写上你的main方法所在的类路径;


2、maven将需要的插件加载完后,可以直接在IDEA的窗口中点击打包,

如果需要可以先点击”clean”,clean完以后再点击”package”

技术图片


最后会在target中生成两个jar包,一个是包含所有依赖的jar:clickLog-1.0-SNAPSHOT.jar

一个是没有依赖的jar:original-clickLog-1.0-SNAPSHOT.jar

技术图片

IDEA结合maven将依赖都打入jar包

标签:blog   pad   build   hot   col   artifact   assembly   resource   tool   

原文地址:https://www.cnblogs.com/weiyiming007/p/12167685.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!