maven打包分離依賴的jar包和靜態資源


原文:https://blog.csdn.net/jbfx455l/article/details/94382770

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>mes-zip</id>
    <formats>
        <!-- 可以根據自己的需求定義壓縮文件的格式 -->
        <format>zip</format>
    </formats>
    <!-- 不包含根目錄,如果為true,生成的壓縮文件會有一個根目錄 -->
    <includeBaseDirectory>false</includeBaseDirectory>
    <!-- 指定需要壓縮的文件清單 -->
    <fileSets>
        <fileSet>
            <!-- 指定你需要壓縮的文件目錄 -->
            <directory>${project.build.directory}/lib/</directory>
            <!-- 指定壓縮后的文件目錄 -->
            <outputDirectory>lib</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}/config/</directory>
            <outputDirectory>config</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}/</directory>
            <includes>
                <include>*.jar</include>
            </includes>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

  pom

<build>
  <plugins>
    <!-- 這個插件是用來打jar包的 -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
        <!-- 將靜態資源排除出jar包 -->
        <excludes>
          <exclude>static/**</exclude>
          <exclude>templates/**</exclude>
          <exclude>*.*</exclude>
        </excludes>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
            <!-- MANIFEST.MF 中 Class-Path 加入前綴 -->
            <classpathPrefix>lib/</classpathPrefix>
            <!-- jar包不包含唯一版本標識 -->
            <useUniqueVersions>false</useUniqueVersions>
            <!-- 指定啟動類的包路徑 -->
            <mainClass>com.jxzl.Sso8004Application</mainClass>
          </manifest>
          <manifestEntries>
            <!--MANIFEST.MF 中 Class-Path 加入資源文件目錄 -->
            <Class-Path>config/</Class-Path>
          </manifestEntries>
        </archive>
        <!-- 指定打出的jar包路徑 -->
        <outputDirectory>${project.build.directory}</outputDirectory>
      </configuration>
    </plugin>
    <!-- 這個插件是用來復制項目依賴的jar包 -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
          <!-- 自定義 -->
          <id>copy-dependencies</id>
          <phase>package</phase>
          <goals>
            <!-- 復制依賴的jar包 -->
            <goal>copy-dependencies</goal>
          </goals>
          <configuration>
            <!-- 將依賴的jar包復制到該路徑下 -->
            <outputDirectory>${project.build.directory}/lib</outputDirectory>
          </configuration>
        </execution>
      </executions>
    </plugin>
 
    <!-- 這個插件是用來復制項目的靜態資源-->
    <plugin>
      <artifactId>maven-resources-plugin</artifactId>
      <executions>
        <execution>
          <!-- 自定義 -->
          <id>copy-resources</id>
          <phase>package</phase>
          <goals>
            <!-- 復制靜態資源 -->
            <goal>copy-resources</goal>
          </goals>
          <configuration>
            <resources>
              <resource>
                <!-- 指定靜態資源的路徑 -->
                <directory>src/main/resources</directory>
                <!-- 指定需要復制的文件 -->
                <includes>
                  <include>*.*</include>
                  <include>static/**</include>
                  <include>templates/**</include>
                </includes>
              </resource>
            </resources>
            <!-- 指定復制到該目錄下 -->
            <outputDirectory>${project.build.directory}/config</outputDirectory>
          </configuration>
        </execution>
      </executions>
    </plugin>
    <!-- 以上配置后你的文件打包后的文件目錄如下
        -lib
        -config
        -項目名.jar
     -->
    <!-- 這個插件使用來將分離出來的靜態資源和依賴的jar包(就是上面說到的文件目錄),
壓縮成一個zip文件。個人感覺這個蠻方便的 -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <!-- 這個插件需要指定一個配置文件 -->
        <descriptors>
          <descriptor>src/main/resources/assembly.xml</descriptor>
        </descriptors>
      </configuration>
      <executions>
        <execution>
          <!-- 自定義 -->
          <id>make-assembly</id>
          <phase>package</phase>
          <goals>
            <!-- 只執行一次 -->
            <goal>single</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

  么沒辦法把zhixingjar放到zip中  有知道的告知一下

https://blog.csdn.net/jbfx455l/article/details/94382770


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM