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

Posted 秋刀鱼的滋味w

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IDEA结合maven将依赖都打入jar包相关的知识,希望对你有一定的参考价值。

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”

image


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

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

image

以上是关于IDEA结合maven将依赖都打入jar包的主要内容,如果未能解决你的问题,请参考以下文章

maven打包成第三方jar包且把pom依赖包打入进来

Maven项目打Jar包,如何添加依赖

如何在IntelliJ IDEA中检索maven依赖jar包的源码

idea怎么导出Maven依赖的jar包

IDEA中maven如何将jar包导入本地的maven库

IDEA打包jar程序