当前位置: 首页 > article >正文

Maven插件学习(一)——生成可执行的 JAR 文件

默认打包生成的jar是不能够直接运行的,因为带有main方法的类信息不回添加到manifest中(打开jar文件中 META/MANIFEST.MF文件,将无法看到Main-Class行)

maven-shade-plugin插件生成可运行的jar文件,该插件会自动将依赖包生成到jar包中。

maven-assembly-plugin插件生成可运行的jar文件,需要配置属性 jar-with-dependencies才能将依赖包生成到jar包中

maven-shade-plugin插件

配置pom文件如下

<?xml version="1.0" encoding="UTF-8"?>
<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.ch.tech</groupId>
    <artifactId>maven-jar</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.shade.plugin.version>3.6.0</maven.shade.plugin.version>
    </properties>

    <dependencies>
        <!-- SLF4J API -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.6</version>
        </dependency>

        <!-- Log4j2 实现 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
            <version>2.20.0</version>
        </dependency>

        <!-- Log4j2 核心 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.20.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${maven.shade.plugin.version}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configura

http://www.kler.cn/a/610534.html

相关文章:

  • AI时代智慧园区新标杆:华为联合51WORLD打造智能运营中心2.0
  • 六十天Linux从0到项目搭建(第五天)(file、bash 和 shell 的区别、目录权限、默认权限umask、粘滞位、使用系统自带的包管理工具)
  • 文件上传绕过的小点总结(4)
  • Spring Boot响应压缩配置与优化
  • qt QOffscreenSurface详解
  • Linux——进程信号(2)(函数信号与软件信号与硬件中断)
  • 问题:md文档转换word,html,图片,excel,csv
  • 《Git江湖录·分支篇》
  • 阿里巴巴1688类网站高保真原型设计
  • 文献分享: ColXTR——将ColBERTv2的优化引入ColXTR
  • Stable Diffusion 3.0 :一键开启你的AI绘画之旅
  • Rust从入门到精通之入门篇:6.函数
  • SpringBoot中安全的设置阿里云日志SLS的accessKey
  • 26考研——栈、队列和数组_栈(3)
  • 三维空间中点、线、面的关系
  • 详细介绍Qt中用于断言的宏 Q_ASSERT
  • k8s存储介绍(五)PV与PVC
  • 【Rust】使用 Rust 语言实践完整的 TDD(测试驱动开发)流程
  • RK3568 驱动和设备匹配的几种方法
  • STM32F103_LL库+寄存器学习笔记04 - GPIO设置输出模式