idea 中mave 项目如何打jar包
时间: 2023-09-09 12:08:24 浏览: 93
在 IDEA 中使用 Maven 打成可执行的 JAR 包,可以按照以下步骤操作:
1. 在 pom.xml 文件中添加以下插件配置:
```
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>你的主类</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
这里使用了 Maven 的 assembly 插件,配置了 JAR 包的描述符类型为带依赖的 JAR 包,以及指定了主类。
2. 在 IDEA 中进行打包,可以使用 Maven 工具栏中的 package 命令,或者使用快捷键 Ctrl + Shift + F9。
3. 打包完成后,在 target 目录下会生成一个 JAR 包,名称为 ${project.artifactId}-${project.version}-jar-with-dependencies.jar,其中 ${project.artifactId} 和 ${project.version} 分别是 Maven 项目的名称和版本号。
4. 在命令行中运行 JAR 包,使用以下命令:
```
java -jar ${project.artifactId}-${project.version}-jar-with-dependencies.jar
```
其中 ${project.artifactId}-${project.version}-jar-with-dependencies.jar 替换成实际的 JAR 包名称。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)