一個大的maven 項目,結構是一個根pom,下面幾個小的module,包括了appservice-darc,appservice-entity等,其中appservice-darc 依賴了 appservice-entity。java
可是呢,對根項目的pom, 執行mvn clean complie 是沒問題的,可是對 appservice-darc 執行 mvn clean complie是不行的,出現下面錯誤:api
[INFO] ------------------------------------------------------------------------ [INFO] Building appservice-darc 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [WARNING] The POM for com.worepay:appservice-entity:jar:0.0.1-SNAPSHOT is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ appservice- --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 4 resources [INFO] Copying 2 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ appservice- --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 10 source files to F:\dev\SVN\GYF\newAppservice\appservice-\target\classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /F:/dev/SVN/GYF/newAppservice/src/main/java/com/worepay/appservice//Banner.java:[3,25] 程序包javax.persistence不存在 [ERROR] /F:/dev/SVN/GYF/newAppservice/src/main/java/com/worepay/appservice//Banner.java:[4,25] 程序包javax.persistence不存在 [ERROR] /F:/dev/SVN/GYF/newAppservice/src/main/java/com/worepay/appservice//Banner.java:[5,25] 程序包javax.persistence不存在 [ERROR] /F:/dev/SVN/GYF/newAppservice/src/main/java/com/worepay/appservice//Banner.java:[8,2] 找不到符號 符號: 類 Table [ERROR] /F:/dev/SVN/GYF/newAppservice/src/main/java/com/worepay/appservice//Banner.java:[12,10] 找不到符號 符號: 類 Id 位置: 類 com.worepay.appservice..Banner [ERROR] /F:/dev/SVN/GYF/newAppservice/src/main/java/com/worepay/appservice//Banner.java:[13,10] 找不到符號 符號: 類 Column 位置: 類 com.worepay.appservice..Banner [ERROR] /F:/dev/SVN/GYF/newAppservice/src/main/java/com/worepay/appservice//Banner.java:[17,10] 找不到符號 符號: 類 Column
IDEA中項目源碼中是沒有錯誤的,說明編譯是ok的,可是執行maven compile 就是不行。。 檢查發現 persistence-api-1.0.jar 依賴也確實是存在的。可是爲何mvn操做就老是不行呢?oracle
appservice-darc 依賴了 appservice-entity,而從上面的日誌看, appservice-entity好像有什麼問題。。 pom 爲何是 invalid ? 打開pom 是沒用任何錯誤提示的呢, 那就奇怪了。。app
後面經過maven 調試發現(添加 -X 參數 ),發現appservice-entity確實仍是有問題的。緣由是appservice-entity 的pom 引用了一個本地的jar,它的寫法是 相對路徑,從而致使appservice-entity 所依賴的全部jar都不可用了,以下:maven
<dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc7</artifactId> <version>12.1.0.1.0</version> <scope>system</scope> <systemPath>${project.basedir}/lib/ojdbc14_g.jar</systemPath> </dependency>
從而,maven compile 失敗了。 怎麼解決呢? 提示告訴我,須要寫成絕對路徑的形式。 把那個本地jar 的地址改成絕對路徑就行了:ui
<dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc7</artifactId> <version>12.1.0.1.0</version> <scope>system</scope> <systemPath>F:/dev/SVN/GYF/rxw/newAppservice/appservice-entity/lib/ojdbc14_g.jar</systemPath> </dependency>
不過,發現 還行須要先把appservice-entity 先install,不install 還不行。我開始就是compile了一下,覺得都在一個項目了, 應該不至於那麼傻,引用不到吧。結果還真是,仍是報以前同樣的錯誤。後面只有乖乖的install 一下,結果就行了。spa
觀察發現,appservice-darc 是從本地maven 倉庫中去獲取appservice-entity 的jar , 由於單單是maven compile,不能要保證本地倉庫中的appservice-entity 已是最新的,是沒用的。若是事先對appservice-entity執行clean compile,那麼clean 操做會清除本地倉庫對應的 jar, 因此本地倉庫中的appservice-entity 是不存在的,僅僅存在於當前項目的target目錄。debug