maven项目打包jar加上导入的依赖一起

Two ways to create jar file in IntelliJ

  1. Creating artifact from IntelliJ
  2. Using maven-assembly-plugin

Creating artifact from IntelliJ:
• Go to project structure:
在这里插入图片描述

• Create a new artifact:
在这里插入图片描述

• Select the main class, and be sure to change the manifest folder:
在这里插入图片描述

You have to change manifest directory:
\src\main\java
replace “java” with “resources”
\src\main\resources
This is how it should look like:
在这里插入图片描述

• Then you choose the dependencies what you want to be packed IN your jar, or NEAR your jar file. Check include in project build
在这里插入图片描述

• To build your artifact go to build artifacts and choose “rebuild”. It will create an “out” folder with your jar file and its dependencies.
在这里插入图片描述

• Click build
• This procedure will create the jar file under the “out” folder

  1. Using maven-assembly-plugin
    • Add build section to the pom file
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <finalName>ServiceCreate</finalName>
                    <appendAssemblyId>false</appendAssemblyId>
                    <archive>
                        <manifest>
                            <mainClass>com.svt.optimoo.App</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

Note : Change the highlighted [art with your packageName.ClassName
• Create a new run/debug configuration:
在这里插入图片描述

• Choose application:
在这里插入图片描述

• Fill in the form
• Add the “assembly:single” maven goal after build to be executed last
在这里插入图片描述
在这里插入图片描述

• Save it, then run
在这里插入图片描述

This procedure will create the jar file under the “target” folder

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值