views:

8321

answers:

6

I am using Maven (and the Maven Eclipse Integration) to manage the dependencies for my Java projects in Eclipse. The automatic download feature for JAR files from the Maven repositories is a real time saver. Unfortunately, it does not include API documentation and source code.

How can I set up Maven to automatically also get the source and javadoc attachments and register them properly with Eclipse?

+6  A: 
mvn eclipse:eclipse -DdownloadSources=true

or

mvn eclipse:eclipse -DdownloadJavadocs=true
Stephen Denne
or both!mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=trueThis only works if the source and javadocs were provided to the repo you're downloading from. Sometimes they aren't provided like Spring.
Spencer K
+2  A: 

There is also a similiar question that answers this and includes example pom settings.

belgarat
+5  A: 

I am sure m2eclipse Maven plugin for Eclipse - the other way around - can do that. You can configure it to download both the source files and javadoc automatically for you.

mrembisz
Yes, I just started using m2eclipse, and it does take car of this (and many other things maven).
Thilo
Neither of these replies are answers. Why are they being voted up? I was able to download the sources by control-clicking the project in Navigator view and choosing "m2 Maven"-->"Download Sources". I was then able to command-click (mac) on the class to navigate to the linked source.
Alex Worden
+1  A: 

If you are using meclipse do

window --> maven --> Download Artifact Sources (select check)

(If you still get attach source window, then click on attach file button and close the attach source window. The next time you try to see the source it will open the correct source)

Surajz

surajz
+5  A: 

The other answers on this work, but if you want to avoid having to remember command line arguments, you can also just add to the downloadSources and downloadJavadocs config to the maven-eclipse-plugin section of your pom.xml:

<project>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                    ... other stuff ...
                </configuration>
            </plugin>
        </plgins>
    </build>
    ...
</project>
overthink
A: 

If the source jars are in the local repository and you are using Eclipses maven support the sources are getting automatically attached. You can run mvn dependency:sources to download all source jars for a given project. Not sure how to do the same with the documentation though.

Hardy