1
请问, Java 如何打出自带依赖的 jar 包?
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 包?
各位好,我想请教,Java 如何打出自带依赖的 jar 包?就是那种拷贝 jar 包到干净的 OpenJDK 环境下就直接可运行的那种?
我现在是依赖 IDEA 的 build artifacts 功能,但是找不到对应的命令行命令,我想在 CI 里完成这件事情。
我使用的是 Java 8 和 Maven.
7 条回复 • 2021-09-23 17:31:26 +08:00
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>
```
```
<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>
```
cslive 1 天前 1
springboot 用 spring-boot-maven-plugin 这个插件,不带容器的 java 非 java ee 项目需要自己写配置文件,指定 main 方法才行
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK