各位好,我想请教,Java 如何打出自带依赖的 jar 包?就是那种拷贝 jar 包到干净的 OpenJDK 环境下就直接可运行的那种?
我现在是依赖 IDEA 的 build artifacts 功能,但是找不到对应的命令行命令,我想在 CI 里完成这件事情。
我使用的是 Java 8 和 Maven.
感谢。
|      1billlee      2021-09-22 18:58:49 +08:00  2 maven shade plugin | 
|  |      2sutra      2021-09-22 19:03:37 +08:00  1 spring-boot-maven-plugin 也可以 https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#goals-repackage | 
|  |      3AllenHua      2021-09-22 19:11:39 +08:00 via iPhone  1 https://hellodk.cn/post/727 ``` <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</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>3.2.0</version> <configuration> <archive> <manifest> <!-- 运行 jar 包时运行的主类,要求写全类名 需要包含 package name --> <mainClass>MainService</mainClass> <!-- 是否指定项目 classpath 下的依赖 --> <addClasspath>true</addClasspath> </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> </build> ``` | 
|      4ztcaoll222      2021-09-22 19:36:06 +08:00  1 关键词:fat jar | 
|      5Jooooooooo      2021-09-22 23:20:20 +08:00  1 感觉你想要的是 fat jar 包含所有的东西 | 
|      6cslive      2021-09-23 09:13:43 +08:00  1 springboot 用 spring-boot-maven-plugin 这个插件,不带容器的 java 非 java ee 项目需要自己写配置文件,指定 main 方法才行 | 
|  |      7monkeydream      2021-09-23 17:31:26 +08:00  1 maven-assembly-plugin 插件了解一下 | 
|  |      8nanmu42 OP 感谢各位的分享,综合意见,最后我使用了 Maven Shade Plugin,目前状态不错。 https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html | 
|      9Muyiafan      2021-09-24 13:35:41 +08:00  1 如果用的是 gradle 构建工具的话。 ``` gradle assemble ``` | 
|  |      10wucao219101      2021-09-24 14:31:34 +08:00  1 maven-assembly-plugin / maven-shade-plugin 二选一,如果是 Spring 项目推荐用 maven-shade-plugin 。 https://xxgblog.com/2015/08/07/maven-create-executable-jar/ |