2

Note that this is source jars - not compiled jars.

Assuming I have the following:

<dependency>
    <groupId>org.swinglabs</groupId>
    <artifactId>swingx</artifactId>
    <version>0.9.2</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/swingx-0.9.3.jar</systemPath>
</dependency>

How do I add my source jars so they can be referenced in eclipse? (I know I can right-click and add to the jar as source - but I wanted a maven import to do this automatically)

Tarod
  • 6,732
  • 5
  • 44
  • 50
hawkeye
  • 34,745
  • 30
  • 150
  • 304
  • Can you explain the reason why you want to do this? What do you expect that Maven does with these on the build class path? Compile the packaged source files? – nwinkler Mar 19 '12 at 11:34
  • Are you using m2e in Eclipse? – nwinkler Mar 19 '12 at 11:38
  • possible duplicate of [Get source jar files attached to Eclipse for Maven-managed dependencies](http://stackoverflow.com/questions/310720/get-source-jar-files-attached-to-eclipse-for-maven-managed-dependencies) – Nishant Mar 19 '12 at 11:41
  • This is not a duplicate - it's not about downloading jars - it's about adding local jars in the project because they can't be downloaded. – hawkeye Mar 19 '12 at 12:00
  • I've added to my answer to show how to handle files that are not available in a public repository. – nwinkler Mar 19 '12 at 12:37

2 Answers2

1

If you're using the m2e Eclipse plugin, there's an option to download sources for all dependencies:

  • Right-click the project
  • Maven > Download Sources

If you're not using m2e, you can download the sources from command line using

mvn dependency:sources

To get them into Eclipse, you can use

mvn eclipse:eclipse -DdownloadSources=true

The easiest way to handle this is through m2e though. I strongly recommend to install it, as it will simplify all other Maven handling from within Eclipse.

If the sources are not available in a public repository, you can either

Out of the two, the first one (local Maven repository/proxy) is recommended.

nwinkler
  • 52,665
  • 21
  • 154
  • 168
0

Never tried but this should work

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

this would also do

 mvn -Declipse.downloadSources=true eclipse:eclipse

see this http://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html#downloadSources

Nishant
  • 54,584
  • 13
  • 112
  • 127
  • This is for jars that can't be downloaded - they exist locally in a directory – hawkeye Mar 19 '12 at 12:00
  • oh, I was confused by previous version of your question. So, you do not have `swingx-version-source.jar` in your local repo? – Nishant Mar 19 '12 at 12:07