1. 程式人生 > 其它 >maven 打包(zip)

maven 打包(zip)

技術標籤:Java

Main下新增檔案

下新增assembly—package.xml

<?xml version='1.0' encoding='UTF-8'?>
<assembly>
    <!--打包名稱,唯一標識-->
    <id>${project.build.finalName}</id>
    <!--打包格式,可以手動修改-->
    <formats>
        <format>zip</format>
    </formats>
    <!--檔案設定-->
    <fileSets>
        <fileSet>
            <!--目標目錄,會處理目錄裡面的所有檔案-->
            <directory>${project.basedir}/src/main/resources</directory>
            <!--相對於打包後的目錄-->
            <outputDirectory>config</outputDirectory>
            <!--檔案過濾-->
            <includes>
                <include>*.*</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>${project.basedir}/src/main/bin</directory>
            <outputDirectory>bin</outputDirectory>
            <includes>
                <include>*.*</include>
            </includes>
            <!--檔案許可權-->
            <fileMode>0755</fileMode>
            <!--如果是指令碼,一定要改為unix.如果是在windows上面編碼,會出現dos編寫問題-->
            <lineEnding>unix</lineEnding>
        </fileSet>


        <!-- 將第三方依賴打包到lib目錄中 -->
        <fileSet>
            <directory>${basedir}/target/lib</directory>
            <outputDirectory>lib</outputDirectory>
            <fileMode>0755</fileMode>
        </fileSet>

        <!-- 將專案啟動jar打包到boot目錄中 -->
        <fileSet>
            <directory>${basedir}/target</directory>
            <outputDirectory>lib</outputDirectory>
            <fileMode>0755</fileMode>
            <includes>
                <include>${project.name}.jar</include>
            </includes>
        </fileSet>

    </fileSets>

</assembly>

新增bin

在main下新增bin 新增bat

Bat檔案

@echo off

rem startup jar
cd ../lib
java -jar logmm.jar
pause

Pom.xml

<build>
        <finalName>${project.name}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.4.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <!--主要使用的是maven提供的assembly外掛完成-->
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <configuration>
                            <appendAssemblyId>false</appendAssemblyId>
                            <!--具體的配置檔案-->
                            <descriptors>${project.basedir}/src/main/assembly/package.xml</descriptors>
                        </configuration>
                        <id>make-assembly</id>
                        <!--繫結到maven操作型別上-->
                        <phase>package</phase>
                        <!--執行一次-->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>