close

  試著用OSGi建構工具Pax的pax-create-project去建立一個新Project,它是以Maven為基礎建立。然後在Eclipse import這個Maven Project,結果除了原來那個artifact ID的project以外,還在Project Explorer另外建立4個project:compiled-bundle-settings、provision、shared-plugin-settings、wrapper-bundle-settings,徒增困擾之餘,只好先研究Maven的modules是怎麼回事,使用pax-create-project建出來的目錄結構如下,artifact id是my:

\my

├ pom.xml  (artifact id parent project)

├ \poms 

︱├ pom.xml  (artifact id = shared-plugin-settings)

︱├ \compiled

︱︱ └ pom.xml (artifact id = compiled-bundle-settings)

︱└ \wrappers

︱   └ pom.xml  (artifact id = wrapper-bundle-settings)

└ \provision

    └ pom.xml (artifact id = provision)

  以上五個pom.xml的artifact id會在Eclipse一共建立五個project,parent project的pom.xml裡所引用dependencies、properties等會被子pom.xml繼承引用,父子關係在pom.xml建立方向如下:

父pom.xml設定:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>examples</groupId>
  <artifactId>my</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>   <!-- 表示只產出pom架構而已 -->

  <modules>
    <module>poms</module>       <!-- 對映到\poms子目錄 -->
    <module>provision</module>    <!-- 對映到\provion子目錄 -->
  </modules>
</project>

子pom.xml設定(以provision為例):

<project>
  <parent>   <!-- 正好對映到父pom.xml的座標 -->
    <groupId>examples</groupId> 
    <artifactId>my</artifactId>
    <version>1.0.0</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>
  <groupId>examples.my.build</groupId>
  <artifactId>provision</artifactId>
  <packaging>pom</packaging>
</project>

  那該如何解決一次開啟多個project的困擾?目前知道的作法也很簡單,在parent directory(my)上一層目錄(假設為demo)再建一個pom.xml,可以只留很單純的座標即可。而Eclipse import Maven Project時就選demo目錄而不是my,這樣只會在Project Explorer產出一個叫demo的project。

  Maven分Module的用意,可以把每個module區分專門處理前端、Spring或JPA等。而我猜Pax這樣建構出不同的專案檔也有意義在,因為OSGi是可插拔的獨立元件開發,這在協同作業上會分工更加精細。

  後來再retry一下,如下圖,在import Maven project選擇根目錄後,有多個pom.xml可勾選,只勾最上面的parent也可以達成Project Explorer只開一個project的目的。

image

arrow
arrow
    全站熱搜

    Jemmy 發表在 痞客邦 留言(0) 人氣()