首页 > 其他分享 >SpringBoot打jar包

SpringBoot打jar包

时间:2023-05-26 20:13:28浏览次数:28  
标签:xml project SpringBoot lib plugin jar maven

pom

<build>
    <plugins>
        <!-- 设定JDK版本 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <showWarnings>true</showWarnings>
                <compilerArgs>
                    <arg>-parameters</arg>
                </compilerArgs>
            </configuration>
        </plugin>
        <!--打成jar包;指定main入口方法;排除配置文件;-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <!--MANIFEST.MF Class-Path 加入前缀-->
                        <classpathPrefix>lib/</classpathPrefix>
                        <!--jar包不包含唯一版本标识-->
                        <useUniqueVersions>false</useUniqueVersions>
                        <!--指定入口-->
                        <mainClass>com.sinovatio.owls.kapp.KApp</mainClass>
                    </manifest>
                    <manifestEntries>
                        <!--MANIFEST.MF 中 Class-Path 加入资源文件目录-->
                        <Class-Path>./config/</Class-Path>
                    </manifestEntries>
                </archive>
                <excludes>
                    <exclude>**/*.yml</exclude>
                    <exclude>**/*.properties</exclude>
                    <exclude>**/*.yaml</exclude>
                    <exclude>**/logback-core.xml</exclude>
                </excludes>
            </configuration>
        </plugin>
        <!--上面第三方包路径加了lib,下面拷贝第三方包到lib-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                            ${project.build.directory}/lib/
                        </outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <!--assembly: 整理所有资源,打成压缩包-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <appendAssemblyId>false</appendAssemblyId>
                <!--最终包名-->
                <finalName>${project.artifactId}-${project.version}</finalName>
                <descriptors>
                    <descriptor>assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <!--绑定包maven生命周期,直接用maven packge打包-->
            <executions>
                <execution>
                    <id>make-assembly-tar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
    <!--下面的文件不会放入jar包,但是会放在target/classes/这里-->
    <!--后面在assembly.xml配置文件中,再将classes下面这些文件放在合适位置-->
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/**</include>
                <include>**</include>
            </includes>
        </resource>
        <resource>
            <directory>bin</directory>
            <includes>
                <include>**/**</include>
                <include>**</include>
            </includes>
            <targetPath>bin</targetPath>
        </resource>
        <resource>
            <directory>devops</directory>
            <includes>
                <include>**/**</include>
                <include>**</include>
            </includes>
            <targetPath>devops</targetPath>
        </resource>
    </resources>
</build>

pom说明

maven-jar-plugin的作用:
	* 将项目打成jar包
	* 指定项目的main方法为项目入口
	* 将项目的配置文件脱离jar包,并加上前径,如config/
	* 将项目的依赖包脱离jar包,并加上路径,如lib/
maven-dependency-plugin的作用:
	* 将项目依赖的jar包,放入lib/下面(这里需要和上面一致)
maven-assembly-plugin的作用:
	* 将项目所有资源,打成一个压缩包,如xxx.tar.gz(其实就是归整target目录下的资源)

assembly.xml

注意:assembly.xml文件位置和pom.xml一致,是在项目的根目录下。

<assembly
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0";
        xmlns:xsi="http://www.w3.org/2001/xmlschema-instance";
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">;
    <id>release</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>true</includeBaseDirectory>
    <fileSets>
        <!--*.properties,*.yml配置文件输出到config目录-->
        <fileSet>
            <directory>${project.build.directory}/classes</directory>
            <outputDirectory>config</outputDirectory>
            <includes>
                <include>**.properties</include>
                <include>**.yaml</include>
                <include>**.yml</include>
                <include>**.xml</include>
            </includes>
        </fileSet>

        <!--依赖包输出到lib目录-->
        <fileSet>
            <directory>${project.build.directory}/lib</directory>
            <outputDirectory>lib</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>

        <!--启动脚本输出到bin目录-->
        <fileSet>
            <directory>${project.build.directory}/classes/bin</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>**.sh</include>
            </includes>
        </fileSet>


        <!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 -->
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly> 

标签:xml,project,SpringBoot,lib,plugin,jar,maven
From: https://www.cnblogs.com/zhujinchong/p/17435705.html

相关文章

  • 把本地的jar包添加到工程中,当maven打包时自动带上本地的jar包
    1,先把本地jar包放到工程的resources目录下面2,然后在pom.xml中添加依赖<dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.55</version><scope>syste......
  • springboot添加多个环境的配置文件
    1,在resources目录下面新建application.properties,application-dev.properties,application-pre.properties,application-prod.properties2,在application.properties只添加一行要激活的环境,其他不用添加spring.profiles.active=dev3,其他属性文件根据需要配置不同的属性......
  • windows设置jar包开机自启
    @echooff@REM------------根据端口关闭java服务------------@REM有多少服务关闭多少端口setport1=9081for/f"tokens=1-5"%%iin('netstat-ano^|findstr":%port1%"')dotaskkill/f/pid%%m&setport1=8082for/f"tokens=1-5"%%iin(......
  • springboot2.7使用log4j2的maven配置
    先排查自带的<!--排除自带的--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId><exclusions>......
  • Jar包的清单文件manifest.MF
    如何在Java中使用JARManifest文件[摘录](如何在Java中使用JARManifest文件(附实例)-掘金(juejin.cn))在Java编程语言中,清单文件是一个文本文件,它包含与程序员的JAR归档文件中包含的文件有关的元数据。这种元数据的范围可以从与包信息有关的信息到安全属性的属性。一个程序在......
  • SpringBoot集成JWT(极简版)
    话不多说,直接上代码接口统一前缀设置importorg.springframework.context.annotation.Configuration;importorg.springframework.web.bind.annotation.RestController;importorg.springframework.web.servlet.config.annotation.PathMatchConfigurer;importorg.springframewo......
  • JAVA语言springboot框架实现的求职招聘管理系统
    技术架构技术框架:SpringBoot+FreeMarker+JPA+MySQL5.7运行环境:jdk8+IntelliJIDEA+maven3+宝塔面板宝塔部署教程回到IDEA,点击编辑器右侧maven图标,执行package,完成后就会在根目录里生成一个target目录,在里面会打包出一个jar文件。宝塔新建一个数据库,导入数据库文件......
  • JAVA语言开发springboot框架实现的自动化立体智慧仓库WMS
    技术架构技术框架:SpringBoot+layui+HTML+CSS+JS运行环境:jdk8+IntelliJIDEA+maven3+宝塔面板宝塔部署教程回到IDEA,点击编辑器右侧maven图标,执行package,完成后就会在根目录里生成一个target目录,在里面会打包出一个jar文件。宝塔新建一个数据库,导入数据库文件,数据......
  • 基于 python 的 nexus 私服 jar 包匹配查找程序
    程序通过计算jar包的sha1摘要,到maven仓库查询对应路径,适用于NexusRepositoryManagerOSS2.14.11-01,其他版本未做测试注意:jar包路径中不要出现空格#!/usr/bin/python3importhashlibimportosimportrequestsimportsysimporttempfilefromxml.etreeimport......
  • idea显示springboot多服务启动界面service
    如果是多模块的微服务,idea提供了一个可以多服务启动的界面services,如果你的项目里没看到这个界面:那么你需要在顶级的maven工程中找到这个配置,然后找到componentname="RunDashboard"这个节点整个替换掉:<componentname="RunDashboard"><optionname="configurationTypes">......