美文网首页
Maven 打包成 zip

Maven 打包成 zip

作者: 林万程 | 来源:发表于2021-01-21 16:18 被阅读0次
  <build>
    <finalName>打出来的包名</finalName>
    <plugins>

      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <classpathPrefix>lib/</classpathPrefix>
              <mainClass>主类带包路径</mainClass>
            </manifest>
            <manifestEntries>
              <Class-Path>./</Class-Path>
            </manifestEntries>
          </archive>
          <excludes>
            <exclude>application.yml</exclude>
          </excludes>
        </configuration>
      </plugin>

      <!-- 比 maven-resources-plugin 灵活 -->
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>

          <!-- 拷贝配置文件和脚本文件 -->
          <execution>
            <id>base</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <!-- http://ant.apache.org/manual/Tasks/ -->
              <target>
                <copy todir="${project.build.directory}/" overwrite="true">
                  <fileset dir="${project.build.scriptSourceDirectory}"/>
                </copy>
                <!-- 默认false,这里加上去是为了方便临时修改 -->
                <copy todir="${project.build.directory}/" overwrite="false">
                  <fileset dir="${project.basedir}/src/main/resources">
                    <include name="application.yml"/>
                  </fileset>
                </copy>
              </target>
            </configuration>
          </execution>

          <!-- 把相关文件压缩成zip包 -->
          <execution>
            <id>zip</id>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <!-- http://ant.apache.org/manual/Tasks/ -->
              <target>
                <zip destfile="${project.build.directory}/${project.build.finalName}.zip">
                  <fileset dir="${project.basedir}/../" includes="README.md"/>
                  <fileset dir="${project.build.directory}/">
                    <include name="${project.build.finalName}.jar"/>
                    <include name="application.yml"/>
                    <include name="static/"/>
                    <include name="*.sh"/>
                    <include name="*.sql"/>
                    <include name="*.bat"/>
                    <include name="lib/"/>
                    <exclude name="lib/spring-boot-devtools*"/>
                  </fileset>
                </zip>
              </target>
            </configuration>
          </execution>

          <!-- 压缩zip包但不包含lib文件夹 -->
          <execution>
            <id>zip_no_lib</id>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <!-- http://ant.apache.org/manual/Tasks/ -->
              <target>
                <zip destfile="${project.build.directory}/${project.build.finalName}_no_lib.zip">
                  <fileset dir="${project.basedir}/../" includes="README.md"/>
                  <fileset dir="${project.build.directory}/">
                    <include name="${project.build.finalName}.jar"/>
                    <include name="application.yml"/>
                    <include name="static/"/>
                    <include name="*.sh"/>
                    <include name="*.sql"/>
                    <include name="*.bat"/>
                  </fileset>
                </zip>
              </target>
            </configuration>
          </execution>

        </executions>
      </plugin>

    </plugins>
  </build>

  <profiles>
    <!-- 拷贝依赖到 lib 目录 -->
    <profile>
      <id>lib</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-dependencies</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/lib</outputDirectory>
                  <overWriteReleases>false</overWriteReleases>
                  <overWriteSnapshots>false</overWriteSnapshots>
                  <overWriteIfNewer>true</overWriteIfNewer>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

相关文章

  • Maven 打包成 zip

  • 2018-09-15

    springboot中自动化打包部署 目录一、maven插件二、目的--1、打包成zip格式,目录结构--2、将包...

  • ubuntu zip/unzip使用

    zip命令 将test目录下打包成myfile.zip。运行实例: unzip命令 将myfile.zip.解压到...

  • 02环境配置-Maven-windows

    下载地址 maven官方 在link中找到编译好的zip‘apache-maven-3.5.3-bin.zip’ ...

  • Dataturks 标注 & 新类别处理

    1. 图片文件夹 打 zip 包上传 图片文件夹日期命名,如 20191015,文件夹打包成 20191015.z...

  • maven打包

    背景 spring boot工程,打包成zip发布,zip包内有bin、lib、config目录。bin目录为启动...

  • 安装配置maven

    下载安装maven 下载Maven,例如apache-maven-3.8.6-bin.zip[https://dl...

  • Python3:zip()和*zip()函数

    描述 zip() 函数用于将可迭代的对象作为参数,将对象中对应的元素打包成一个个元组 *zip() 和zip()配...

  • Python3-demo-备份文件并打包 zip

    备份文件并打包成 zip 需要备份的文件目录,打包后的目录 打包 zip zip 文件名由时间命名示例代码 输出信...

  • Maven安装教程

    下载apache-maven-3.3.9-bin.zip 解压目录:D:\software\Maven\apach...

网友评论

      本文标题:Maven 打包成 zip

      本文链接:https://www.haomeiwen.com/subject/wqijxktx.html