Search code examples
maven-2m2eclipse

How to teach Eclipse to include Maven source packages on the source path?


How can I teach Eclipse with m2eclipse to include all source .jar in my local Maven repository in the source path when looking up library source files while debugging?


Solution

  • I was having this exact same problem-- I used the Maven Source Plugin to deploy the source to our repo, and when I included that project in a separate one, try as I might, it wouldn't include the source on the Eclipse build path. I had done this before for a previous job and I knew it was possible to have the source included on the buildpath so that Eclipse will automatically link the source in the integrated debugger simply by clicking "Download Sources" as described in the other answers.

    Here is what I had (which was not working for me). I had gotten this snippet of code from the maven-source-plugin's webpage:

            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
    

    This would package the source in a separate JAR and upload it to our repo, but it wouldn't automatically attach to the Eclipse debugger. Eventually, I found that I needed a <configuration><attach>true</attach></configuration> snippet included, like so:

            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <attach>true</attach>
            </configuration>
    

    After this, the source automatically attaches to the Eclipse debugger by right-clicking on the project in Package Explorer and doing "Maven > Download Sources".

    I hope this solves your problem.