1

请问, Java 如何打出自带依赖的 jar 包?

 2 years ago
source link: https://www.v2ex.com/t/803460
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
请问, Java 如何打出自带依赖的 jar 包?

V2EX  ›  Java

请问, Java 如何打出自带依赖的 jar 包?

  nanmu42 · 1 天前 · 1407 次点击

各位好,我想请教,Java 如何打出自带依赖的 jar 包?就是那种拷贝 jar 包到干净的 OpenJDK 环境下就直接可运行的那种?

我现在是依赖 IDEA 的 build artifacts 功能,但是找不到对应的命令行命令,我想在 CI 里完成这件事情。

我使用的是 Java 8 和 Maven.

7 条回复    2021-09-23 17:31:26 +08:00

billlee

billlee   1 天前   ❤️ 2

maven shade plugin

AllenHua

AllenHua   1 天前 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>
```

ztcaoll222

ztcaoll222   1 天前   ❤️ 1

关键词:fat jar

Jooooooooo

Jooooooooo   1 天前   ❤️ 1

感觉你想要的是 fat jar

包含所有的东西

cslive

cslive   1 天前   ❤️ 1

springboot 用 spring-boot-maven-plugin 这个插件,不带容器的 java 非 java ee 项目需要自己写配置文件,指定 main 方法才行

monkeydream

monkeydream   15 小时 46 分钟前

maven-assembly-plugin 插件了解一下

关于   ·   帮助文档   ·   FAQ   ·   API   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   3257 人在线   最高记录 5497   ·  

创意工作者们的社区

World is powered by solitude

VERSION: 3.9.8.5 · 21ms · UTC 01:17 · PVG 09:17 · LAX 18:17 · JFK 21:17
♥ Do have faith in what you're doing.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK