新增與其他模組的相依關係

您可以在 pom.xml 檔中或使用 POM 編輯器,將 addClasspath 元素設為 true,來新增與其他模組的相依關係。

關於這項作業

重要: 適用於 Liberty 和 WebSphere® Application Server 傳統版

程序

  1. 在 pom.xml 原始檔中,將 addClasspath 設為 true。
    1. 開啟 pom.xml 檔,並存取程式碼視圖。 如果要存取程式碼視圖,請用滑鼠右鍵按一下專案中的 pom.xml 檔,並選取開啟工具 > Maven POM 編輯器。按一下 pom.xml 標籤。
    2. 尋找要更新的正確 <plugin> 區段。 尋找對應至您專案類型的 <plugin><artifactID> 區段。例如,轉換成 Maven 專案的 Web 專案會將 artifactID 設為 maven-war-plugin。轉換後的 EJB 專案會將 artifactID 設為 maven-ejb-plugin。 下列範例顯示含有 artifactID maven-war-plugin 的 <plugin> 區段:
      <plugin>
         <artifactId>maven-war-plugin</artifactId>
         	<version>2.2</version>
         <configuration>
            <warSourceDirectory>WebContent</warSourceDirectory>
            <failOnMissingWebXml>false</failOnMissingWebXml>
         </configuration>
      </plugin>
    3. 更新 <configuration> 區段,以將 addClasspath 設為 true。 將下列程式碼新增到 configuration 區段內:
      <archive>
         <manifest>
            <addClasspath>true</addClasspath>
         </manifest>
      </archive>
      下列範例顯示 maven-war-plugin 構件的完整區段,其中 addClasspath 設為 true。
      <plugin>
         <artifactId>maven-war-plugin</artifactId>
         	<version>2.2</version>
         <configuration>
            <warSourceDirectory>WebContent</warSourceDirectory>
            <failOnMissingWebXml>false</failOnMissingWebXml>
            <archive>
               <manifest>
                  <addClasspath>true</addClasspath>
               </manifest>
            </archive>
         </configuration>
      </plugin>
  2. 使用 POM 編輯器的「相依關係」標籤,來新增相依關係。 按一下相依關係標籤。按一下新增,以存取「選取相依關係」對話框。輸入您想新增作為相依關係之模組的值。完成時,請按一下確定。
    註: 一旦將相依關係新增至 Web 專案,依預設,WEB-INF/lib 位置中會包含該相依關係。如果配置 maven-war-plugin,以在 MANIFEST.MF 檔中新增類別路徑,則 MANIFEST.MF 檔和 WEB-INF/lib 位置兩者中都會包含每一項相依關係。如果您希望只在 MANIFEST.MF 檔中包含該相依關係,請將相依關係標示為選用。如果要將相依關係標示為選用,請在相依關係標籤中,選取該相依關係,並按一下內容按鈕。在內容中,勾選選用方框,並按一下確定。
Icon that indicates the type of topic Task topic
Timestamp icon Last updated: last_date

File name: add_dep.html