溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

java基于maven多模塊合并打包部署的方法是什么

發(fā)布時間:2023-02-24 10:09:07 來源:億速云 閱讀:85 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹“java基于maven多模塊合并打包部署的方法是什么”的相關(guān)知識,小編通過實(shí)際案例向大家展示操作過程,操作方法簡單快捷,實(shí)用性強(qiáng),希望這篇“java基于maven多模塊合并打包部署的方法是什么”文章能幫助大家解決問題。

項(xiàng)目環(huán)境

  • jdk 1.8

  • spring 2.7.x

  • maven 3.6

項(xiàng)目結(jié)構(gòu)

java基于maven多模塊合并打包部署的方法是什么

模塊功能

client – 對外service
common – 共用工具切面等
main – 啟動類
goods – 子模塊具體實(shí)現(xiàn)

模塊間依賴關(guān)系

client – 無依賴
common – 無依賴
main – client、common、goods
goods – client、common

具體POM配置

頂級pom

引入需要被使用的所有項(xiàng)目子模塊,并統(tǒng)一制定版本號

    <groupId>org.ct</groupId>
    <artifactId>gp-data-analysis</artifactId>
    <packaging>pom</packaging>
    <version>${gp-data.version}</version>
    <modules>
        <module>gp-data-client</module>
        <module>gp-data-common</module>
        <module>gp-futrue-goods</module>
        <module>gp-data-main</module>
    </modules>
    
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <gp-data.version>1.0.0</gp-data.version>
    </properties>

	<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.ct</groupId>
                <artifactId>gp-data-analysis</artifactId>
                <version>${gp-data.version}</version>
            </dependency>
            <dependency>
                <groupId>org.ct</groupId>
                <artifactId>gp-data-main</artifactId>
                <version>${gp-data.version}</version>
            </dependency>
            <dependency>
                <groupId>org.ct</groupId>
                <artifactId>gp-data-common</artifactId>
                <version>${gp-data.version}</version>
            </dependency>
            <dependency>
                <groupId>org.ct</groupId>
                <artifactId>gp-data-client</artifactId>
                <version>${gp-data.version}</version>
            </dependency>
            <dependency>
                <groupId>org.ct</groupId>
                <artifactId>gp-data-futrue</artifactId>
                <version>${gp-data.version}</version>
            </dependency>
         </dependencies>
    </dependencyManagement>

	<build>
		<!-- 引入maven打包工具 -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

client、common、goods類似

	<!-- 指定父pom版本 -->
    <parent>
        <artifactId>gp-data-analysis</artifactId>
        <groupId>org.ct</groupId>
        <version>${gp-data.version}</version>
    </parent>

main 設(shè)置打包入口,掃描的xml配置項(xiàng)等
&emsp; &emsp; main 中dependency中引入順序需要注意,需要保證,未被依賴的在前,被依賴的子模塊在后。因?yàn)榇颂幍捻樞驔Q定了maven install的順序

    <parent>
        <artifactId>gp-data-analysis</artifactId>
        <groupId>org.ct</groupId>
        <version>${gp-data.version}</version>
    </parent>
     <dependencies>
        <dependency>
            <groupId>org.ct</groupId>
            <artifactId>gp-data-common</artifactId>
        </dependency>
        <dependency>
            <groupId>org.ct</groupId>
            <artifactId>gp-data-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.ct</groupId>
            <artifactId>gp-data-futrue</artifactId>
        </dependency>
    </dependencies>

	 <build>
        <plugins>
            <!--打包插件-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <goals>
                            <!-- 整合打jar包 -->
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!--支持靜態(tài)文件熱部署-->
                    <addResources>true</addResources>
                    <!-- 指定該Main Class為全局的唯一入口 -->
                    <mainClass>org.ct.gp.GpDataBootApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>

        <!--打包規(guī)則,打包時將resources文件夾打包進(jìn)去-->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
            </resource>

            <!--保證mapper文件夾中的.xml文件可以被編譯-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

使用maven打包root目錄

java基于maven多模塊合并打包部署的方法是什么

生成的main jar,及包含了所有模塊

java基于maven多模塊合并打包部署的方法是什么

關(guān)于“java基于maven多模塊合并打包部署的方法是什么”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點(diǎn)。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI