eclipse在多modules項目結構下避免模組間依賴引用的情境

來源:互聯網
上載者:User

標籤:

這個在單一classLoader時,不會有問題。如果多classloader下會有問題。

假設工程有兩個模組,module2 依賴module1

當我們執行mvc eclipse:eclipse後,然後查看module2下的.classpath檔案,會發現 : <classpathentry kind="src" path="/module1"/>。

如果module1中pom.xml,我們聲明了一個第三方依賴(假設為 servlet-api)scope:provided。 你會發現此時module2中的buildpath還是會有這個第三方依賴(servlet-api)。即使你在module2的pom.xml中在module1排除servlet-api實際還是傳遞存在著的。

通常使用單一appClassLoader情況下,你可能不需要關注這個問題。但如果依靠這些classpath分classLoader問題,就會出現問題。

 

解決方案:

 對項目主pom中聲明maven-eclipse-plugin並配置如下,阻止這種模組引用。

具體說明如下: https://maven.apache.org/plugins/maven-eclipse-plugin/examples/prevent-module-references.html

重新執行mvn eclipse:eclipse 後,再查看module2的.classpath檔案,<classpathentry kind="var" path="M2_REPO/com/xxxx.../{version}/module1-{version}.jar"。此時再檢查buildpath就乾淨了。

 

註:在intellj idea不存在這個問題。

eclipse在多modules項目結構下避免模組間依賴引用的情境

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.