將程式庫新增至 EAR 程式庫目錄
關於這項作業
重要: 適用於 Liberty 和 WebSphere® Application Server 傳統版
程序
- 按兩下 pom.xml 檔,在 POM 編輯器中開啟該檔案。按一下 pom.xml 標籤,以直接處理原始檔。
- 設定要在 EAR 專案中使用的 lib 目錄。 將 <defaultLibBundleDir> 元素新增至 maven-ear-plugin 的配置,如下列範例所示:
<plugins> <plugin> <artifactId>maven-ear-plugin</artifactId> <version>2.7</version> <configuration> <version>6</version> <defaultLibBundleDir>lib</defaultLibBundleDir> </configuration> </plugin> </plugins> - 儲存 pom.xml 檔。
- 使用快速修正程式來解決任何錯誤。 儲存 pom.xml 檔之後,您可能會在問題或標記視圖中,看到下列錯誤:
- Library Directory "<PATH_TO_LIB_FOLDER>" does not exist.
- Project configuration is not up-to-date with pom.xml. Run Maven->Update Project or use Quick Fix.
- 將 JAR 檔放在 lib 目錄中。 如果在 <defaultLibBundleDir> 元素中,將 lib 目錄指定給 EAR 專案,依預設,會在 lib 目錄中組合 JAR 構件的所有相依關係。不過,如果您想將 JAR 檔放在不同位置,可以使用 <jarModule> 元素來指定不同位置。
舉例來說,下列 pom.xml 區段顯示 EAR 專案使用 lib 作為用來組合 JAR 檔的預設目錄:
<plugin> <artifactId>maven-ear-plugin</artifactId> <version>2.7</version> <configuration> <version>6</version> <defaultLibBundleDir>lib</defaultLibBundleDir>在下列範例中,pom.xml 檔與包裝在 lib 中的共用程式庫具有相依關係,以及與 EAR 檔根目錄中所組合的 EJB 用戶端 JAR 檔具有相依關係。不需進一步變更,依預設,這兩者都會組合在 lib 目錄中。<dependencies> <dependency> <groupId>testapp</groupId> <artifactId>ejbclient</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>testapp</groupId> <artifactId>SharedLib</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies>下列範例顯示如何變更 EJB 用戶端 JAR 檔的位置:
這個範例顯示 JAR 檔的預設軟體組目錄是 lib,但是 <artifactId>ejbclient</artifactId> 的 EJB 用戶端 JAR 檔位於專案的根目錄。軟體組目錄以 <bundleDir>/</bundleDir> 指出。<plugin> <artifactId>maven-ear-plugin</artifactId> <version>2.7</version> <configuration> <version>6</version> <defaultLibBundleDir>lib</defaultLibBundleDir> <modules> <jarModule> <groupId>testapp</groupId> <artifactId>ejbclient</artifactId> <bundleDir>/</bundleDir> </jarModule> </modules> </configuration> </plugin>
上層主題: 定義 Java EE 模組相依關係