2012-07-06 43 views
38

在我的項目中,我正在使用通過Maven提供的JAR文件。但Maven給我的只有這個罐子 - 沒有javadocs,也沒有消息來源。按「下載源」不起作用:Eclipse仍然沒有找到jar的來源。如何使用Maven下載jar的源代碼?

這取決於什麼?資料庫應該自動提供來源?

可能我需要在POM中寫些東西來指示Maven下載源代碼?

我現在的POM如下:

<repositories> 
    <repository> 
     <id>xuggle repo</id> 
     <url>http://xuggle.googlecode.com/svn/trunk/repo/share/java/</url> 
    </repository> 
</repositories> 

<dependencies> 

    <dependency> 
     <groupId>xuggle</groupId> 
     <artifactId>xuggle-xuggler</artifactId> 
     <version>5.3</version> 
     <type>rar</type> 
    </dependency> 

</dependencies> 

爲什麼Maven的不說,它的來源任何評論免費下載失敗?

回答

63

執行mvn dependency:sources會強制maven下載項目中所有jar的所有源文件,如果源文件可用(上傳到託管工件的存儲庫中)。如果你想下載的javadoc命令是mvn dependency:resolve -Dclassifier=javadoc

也有可能在你的settings.xml文件創建一個配置文件,其中包括以下屬性:

<properties> 
    <downloadSources>true</downloadSources> 
    <downloadJavadocs>true</downloadJavadocs> 
</properties> 
+0

但如果有在倉庫的Maven沒有源會坐視不管默默地,對不對?沒有錯誤,沒有警告? – 2012-07-06 11:46:29

+0

是的,我想是的,至少如果它沒有在一些非常詳細的/調試模式下運行。也許可以在debug/verbose模式下運行它,grep爲特定的消息。 – hovanessyan 2012-07-06 11:49:28

+0

我添加了一個答案,以將這些屬性添加到maven settings.xml – RaamEE 2014-08-10 07:10:18

3

source/javadoc jar可能沒有提供,也不在存儲庫中 - 沒有任何需要source/javadoc jar的東西存在。

27
mvn dependency:sources 
mvn dependency:resolve -Dclassifier=javadoc 

,如果沒有它的來源應該說像

[INFO] The following files have NOT been resolved: 
[INFO] com.oracle:ojdbc6:java-source:sources:12.1.0.1 
[INFO] javax:javaee-api:java-source:sources:6.0 
3

延伸@hovanessyan答案。

在Maven的settings.xml中啓用downloadSources和downloadJavadocs的基本配置文件如下所示。 例如配置文件ID是downloadSources

<!-- add the profile under profiles section --> 

    <profile> 
     <id>downloadSources</id> 
     <properties> 
      <downloadSources>true</downloadSources> 
      <downloadJavadocs>true</downloadJavadocs>   
     </properties> 
    </profile> 

<!-- activate the profile under activeProfiles section --> 

    <activeProfiles> 
    <activeProfile>downloadSources</activeProfile> 
    </activeProfiles> 
0

在Eclipse中分辯點擊你的項目,然後再Maven>Download SourcesMaven>Download Javadoc

6

這是最好的,因爲它已經過時不依賴於Eclipse插件。使用downloadSourcesdownloadJavadocs屬性對我無效。上面發佈的關於使用依賴關係插件詞的答案。但是,您可能希望自動下載源代碼和javadoc。此外,您可能希望始終創建一個源代碼jar和一個javadoc jar。把它放在你的項目中。如果你使用模塊,把你的父母。

<build> 
    <plugins> 
     <!-- download sources and javadoc --> 
     <plugin> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.10</version> 
      <executions> 
       <execution> 
        <id>download-sources</id> 
        <goals> 
         <goal>sources</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>download-javadoc</id> 
        <configuration> 
         <classifier>javadoc</classifier> 
        </configuration> 
        <goals> 
         <goal>resolve</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <!-- Always create javadoc jar. --> 
     <plugin> 
      <artifactId>maven-javadoc-plugin</artifactId> 
      <version>2.10.4</version> 
      <executions> 
       <execution> 
        <id>attach-javadoc</id> 
        <goals> 
         <goal>jar</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <!-- Always create source jar. --> 
     <plugin> 
      <artifactId>maven-source-plugin</artifactId> 
      <version>2.10</version> 
      <executions> 
       <execution> 
        <id>attach-sources</id> 
        <goals> 
         <goal>jar</goal> 
         <goal>test-jar</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
1

您還可以使用下載target/dependencies下來源:

mvn -Dclassifier=sources dependency:copy-dependencies