一、Eclipse 的引入:
1. 在eclipse windows -> properties->maven 選項,然后查看右側 菜單來中 找到 Download Artifact Sources 選項勾選;如果想要下載JavaDOC 則勾選 DownloadArtifact JavaDOC 選項。點擊apply 並確定。
2.回到eclipse項目中右鍵項目 找到maven 選項選擇 update project... 選項去down最新的代碼,此時 我們所需要的 source 也會被下載下來。
二、Maven命令下載源碼和javadocs
當在IDE中使用Maven時如果想要看引用的jar包中類的源碼和javadoc需要通過maven命令下載這些源碼,然后再進行引入,通過mvn命令能夠容易的達到這個目的:
代碼如下:
mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc
命令使用方法:首先進入到相應的pom.xml目錄中,然后執行以上命令:
第一個命令是嘗試下載在pom.xml中依賴的文件的源代碼。
第二個命令:是嘗試下載對應的javadocs
但是有可能一些文件沒有源代碼或者javadocs
三、通過配置文件添加
打開maven配置文件 setting.xml文件(.../.m2/settings.xml,也只能是你自己單獨下的maven的conf目錄下) 增加如下配置:
代碼如下:
<profiles> <profile> <id>downloadSources</id> <properties> <downloadSources>true</downloadSources> <downloadJavadocs>true</downloadJavadocs> </properties> </profile> </profiles>
<activeProfiles>
<activeProfile>downloadSources</activeProfile>
</activeProfiles>
注意:這里配置文件要和原有的配置文件整合下,放到合適的位置,否則會報錯。
四、配置eclipse
Window > Preferences > Maven and checking the "Download Artifact Sources" and "Download Artifact JavaDoc" options