採用maven的聚合,專案拆分、整合boot cloud時,錯誤的整合思路,如何解決
阿新 • • 發佈:2018-11-11
idea下,如何進行springboot的maven聚合依賴。
首先,把我的專案結構圖大致說明一下:
專案檔案結構大致圖:
對應的pom資訊如下,從父級逐級顯示,以下只是備註自己的關鍵程式碼
jt-parent
<modules> <module>../jt_common</module> </modules> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.9.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency>
jt-common
<parent> <artifactId>jt_parent</artifactId> <groupId>jt_parent</groupId> <version>1.0-SNAPSHOT</version> <relativePath>../jt_parent/pom.xml</relativePath> </parent> <dependency> 依次引入對應的多個jar包 </dependency>
jt-manage
<packaging>war</packaging>
<parent>
<artifactId>jt_parent</artifactId>
<groupId>jt_parent</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../jt_parent/pom.xml</relativePath>
</parent>
jt-web
<packaging>war</packaging> <parent> <artifactId>jt_parent</artifactId> <groupId>jt_parent</groupId> <version>1.0-SNAPSHOT</version> <relativePath>../jt_parent/pom.xml</relativePath> </parent> <!-- 引入工具類 --> <dependency> <groupId>jt_parent</groupId> <artifactId>jt_common</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
專案的結構如下
這個就出現一個問題:
我的專案聚合,準確來說思路可以。但是。如果我再加入註冊服務中心,再加入其它的中心。由於我的父類都是jt-parent。那麼,這樣的方式,導致我一些其它的專案,我本不需要這麼多jar的結構。這樣就稍顯累贅。而且。這樣的獨立性也不好。
我的目的:最後的專案要每個模組,可以單獨開來。形成一個跨域多系統。
問題解決過程:
那麼,這樣就要我的idea裡面,同時顯示多個專案,類似eclipse的工作空間的概念一樣,我這樣的構建,是因為思路被束縛在idea只能顯示單個專案,如果多專案,那麼就要使用子module的情況。其實這是不對的。
Idea也可以實現類似eclipse裡面工作空間的效果。只要直接開啟對應的專案。然後在對應的資料夾裡面整體開啟專案。在“maven project” - “+” - “select path”–選擇對應的pom。
整合後如圖:
專案的結構如圖:還需完善: