zoukankan      html  css  js  c++  java
  • springboot如何打zip包

      在实际项目中,有时项目方要求暴露配置及依赖jar包,此时就不能使用maven自带的打包工具,而需要自己编写配置文件打包。

      1、不使用maven的自动打包工具,使用maven-jar-plugin插件

     1         <plugin>
     2             <groupId>org.apache.maven.plugins</groupId>
     3             <artifactId>maven-jar-plugin</artifactId>
     4             <configuration>
     5                 <archive>
     6                     <manifest>
     7                         <mainClass>com.lz.car.App</mainClass>
     8                         <addClasspath>true</addClasspath>
     9                         <classpathPrefix>lib/</classpathPrefix>
    10                     </manifest>
    11                     <manifestEntries>
    12                         <Class-Path>./</Class-Path>
    13                     </manifestEntries>
    14                 </archive>
    15                 <excludes>
    16                     <exclude>config/**</exclude>
    17                 </excludes>
    18             </configuration>
    19         </plugin>
    20 
    21         <plugin>
    22             <artifactId>maven-assembly-plugin</artifactId>
    23             <configuration>
    24                 <appendAssemblyId>false</appendAssemblyId>
    25                 <descriptors>
    26                     <descriptor>src/main/resources/package.xml</descriptor>
    27                 </descriptors>
    28             </configuration>
    29             <executions>
    30                 <execution>
    31                     <id>make-assembly</id>
    32                     <phase>package</phase>
    33                     <goals>
    34                         <goal>single</goal>
    35                     </goals>
    36                 </execution>
    37             </executions>
    38         </plugin>

      2、编写package.xml文件(注意文件路径在上面pom文件配置中已经指定),定义打包规则

     1 <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
     2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     3     xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
     4     <id>package</id>
     5     <formats>
     6         <format>zip</format>
     7     </formats>
     8     <includeBaseDirectory>true</includeBaseDirectory>  
     9     <dependencySets>
    10         <dependencySet>
    11             <useProjectArtifact>true</useProjectArtifact>
    12             <outputDirectory>lib</outputDirectory>
    13             <excludes>
    14                 <exclude>
    15                     ${groupId}:${artifactId}
    16                 </exclude>
    17             </excludes>
    18         </dependencySet>
    19     </dependencySets>
    20     <fileSets>
    21         <fileSet>
    22             <directory>bin</directory>
    23             <outputDirectory></outputDirectory>
    24         </fileSet>
    25         <fileSet>
    26             <directory>src/main/resources/config/</directory>
    27             <outputDirectory>config</outputDirectory>
    28             <excludes>
    29                 <exclude>logback.xml</exclude>
    30             </excludes>
    31         </fileSet>
    32         <fileSet>  
    33             <directory>${project.build.directory}</directory>  
    34             <outputDirectory></outputDirectory>
    35             <includes>
    36                 <include>*.jar</include>
    37             </includes>
    38         </fileSet>
    39     </fileSets>
    40 </assembly>

      请注意我的配置文件中config为配置文件路径,里面是我的properties配置文件,logback.xml是我的日志配置文件。

  • 相关阅读:
    PHP实现智能语音播报
    scrapy随机切换user-agent
    scrapy 下载器中间件 随机切换user-agent
    scrapy xpath去除空格
    scrapy 爬虫中间件 deepth深度
    scrapy 爬虫中间件 httperror中间件
    scrapy爬虫中间件-urlLength
    转载:Java 内存区域和GC机制
    JavaScript中对象数组 作业题目以及作业
    【转载】解决nginx负载均衡的session共享问题
  • 原文地址:https://www.cnblogs.com/tranquillity/p/9488691.html
Copyright © 2011-2022 走看看