maven學習筆記(一)maven下載javadoc和源碼

Maven命令下載源碼和javadocs

當在IDE中使用Maven時若是想要看引用的jar包中類的源碼和javadoc須要經過maven命令下載這些源碼,而後再進行引入,經過mvn命令可以容易的達到這個目的: java

mvn dependency:sources apache

mvn dependency:resolve -Dclassifier=javadoc eclipse

命令使用方法:首先進入到相應的pom.xml目錄中,而後執行以上命令: maven

第一個命令是嘗試下載在pom.xml中依賴的文件的源代碼。 ui

第二個命令:是嘗試下載對應的javadocs url

可是有可能一些文件沒有源代碼或者javadocs spa


2:經過配置文件添加

打開maven配置文件 setting.xml文件(.../.m2/settings.xml) 增長以下配置: .net

<profiles>
<profile>
    <id>downloadSources</id>
    <properties>
        <downloadSources>true</downloadSources>
        <downloadJavadocs>true</downloadJavadocs>           
    </properties>
</profile>
</profiles>
 
<activeProfiles>
  <activeProfile>downloadSources</activeProfile>
</activeProfiles>

3:配置eclipse

Window > Preferences > Maven and checking the "Download Artifact Sources" and "Download Artifact JavaDoc" options xml


轉者再補充一個方式,在pom.xml添加以下內容:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
        </plugins>

    </build> ip

maven中添加遠程倉庫:

<profile>
      <id>dev</id>
 <repositories>  
<repository>  
 <id>company</id>  
 <name>company</name>  
 <url>http://192.168.2.202:8081/nexus/content/repositories/releases/</url>  
 <releases>  
<enabled>true</enabled>  
 </releases>  
 <snapshots>  
<enabled>false</enabled>  
 </snapshots>  
</repository>  
 </repositories>  
 <pluginRepositories>  
<pluginRepository>  
 <id>company</id>  
 <name>company</name>  
 <url>http://192.168.2.202:8081/nexus/content/repositories/releases/</url>  
 <releases>  
<enabled>true</enabled>  
 </releases>  
 <snapshots>  
<enabled>false</enabled>  
 </snapshots>      
</pluginRepository>  
 </pluginRepositories>    
    </profile>

把URL改寫成本身的:

推薦maven倉庫:

http://mvnrepository.com/
http://search.maven.org/
http://repository.sonatype.org/content/groups/public/
http://people.apache.org/repo/m2-snapshot-repository/

http://people.apache.org/repo/m2-incubating-repository/

同時在pom.xml中的setting中的文件

<activeProfiles>
    <activeProfile>dev</activeProfile>
  </activeProfiles>

從Maven倉庫中導出jar包:進入工程pom.xml 所在的目錄下,輸入:

mvn dependency:copy-dependencies -DoutputDirectory=lib  

相關文章
相關標籤/搜索