普通的maven项目,如何打成一个fat jar(包括了全部依赖jar包)?
2023-09-11 14:21:54 时间
1、前言
用过spring boot的同学肯定知道,现在web项目可以直接打成jar包运行,相当方便。
那么普通项目如何配置(非spring boot),才能打成一个类似的jar包呢?
2、解决方案:
在pom中的build中进行如下配置即可:
<plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <!--这里指定要运行的main类--> <mainClass>netty.client.TcpClient809</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <!-- 此处指定继承合并 --> <phase>package</phase> <!-- 绑定到打包阶段 --> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins>
3、普通java工程,如何获取所有依赖的jar包
If you need to download the jars instead of using a build system, create a Maven pom file like this with the desired version:
<?xml version="1.0"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.netflix.hystrix.download</groupId> <artifactId>hystrix-download</artifactId> <version>1.0-SNAPSHOT</version> <name>Simple POM to download hystrix-core and dependencies</name> <url>http://github.com/Netflix/Hystrix</url> <dependencies> <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId>hystrix-core</artifactId> <version>x.y.z</version> <scope/> </dependency> </dependencies> </project>
Then execute:
mvn -f download-hystrix-pom.xml dependency:copy-dependencies
It will download hystrix-core-*.jar and its dependencies into ./target/dependency/.
You need Java 6 or later.
相关文章
- 如何将maven依赖项打进jar包,将一个完整的项目打进jar包
- [转]Spring——jar包详解
- Maven 打包生成-source.jar源码
- Maven打包生成包含所有依赖的jar包
- SQL state [99999]; error code [17056]; 不支持的字符集 (在类路径中添加 orai18n.jar): ZHS16GBK;
- 使用maven把所有的依赖打成jar
- maven项目导出可执行jar
- Java最快的maven仓库地址,国内Maven地址,超快的Maven地址
- Maven - Maven Build Life Cycle - maven tutorial
- Windows下IDEA run能运行springboot,java -jar maven打的包拉有中文的nacos配置,报org.yaml.snakeyaml.error.YAMLException错误解决
- 如何发布本地maven项目jar包部署到nexus私服?
- maven生成jar包
- maven项目,导入的jar包,没有包含在pom文件中,install失败
- mysql jar包下载(直接链接下载)
- 玩转springcloud:父工程中jar包依赖如何声明才是最优解,哪些需要写,哪些不需要写都总结好了请拿走
- Java魔法堂:打包知识点之jar
- windows下bat脚本启动springboot项目jar包
- maven 依赖文件 pom.xml 编译 mvn compile 运行 不用mvn exec:java -Dexec.mainClass="hello.HelloWorld" 打成jar包 mvn package mvn install http://blog.csdn.net/yaya1943/article/details/48464371
- struts2-dojo-plugin-2.3.1.2.jar!/struts-plugin.xml:29:119
- Guns 将jar包添加到windows服务
- 如何把外部jar包在maven项目的POM中以依赖方式引入?