Eclipse loops endlessly: Invoking 'Maven Project Builder' - eclipse

Ugh! My Eclipse is stuck in an endless loop:
No operations to display at this time
Refreshing Workspace Building
Workspace. Invoking 'Maven Project Builder' on /MobileWebApp
The building workspace never gets past 58%.
Details:
Google's GWT provides a sample app MobileWebApp. They suggest adding it to Eclipse via File > Import > Checkout Maven projects from SCM.
I followed the instructions in this blog for adding the plugins for m2e, subclipse, and the m2e-subclipse connector.
After installing the plugins, I imported the sample project via File > Import > Checkout Maven projects from SCM and this URL.
The import seemed to complete ok and Eclipse doesn't display any markers. But now I have this endless refreshing and building and have no clue what is causing it or how to fix it.
Versions:
Eclipse Indigo 3.7
m2e 1.0.100
m2e connector for build-helper-maven-plugin 0.14
Maven SCM handler for Subclipse 0.13
Subclipse 1.6.18
Subclipse Client Adapter 1.6.12
Any advice is greatly appreciated.

I opened my module's .project file. There were two entries:
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
</buildCommand>
I removed org.eclipse.m2e.core.maven2Builder entry and it magically fixed the problem.

I was able to resolve this by right clicking on the project and selecting Run As > Maven Clean

I was getting the same issue in an eclipse (Juno) Maven project that had nothing to do with GWT - it just kept refreshing and "Invoking Maven Project Builder". Going to the Progress view and requesting a cancellation of either progress entry (by clicking that red stop button on the right) didn't help.
The project the builder kept getting stuck on was always the same, and a couple of levels deep in a set of multi-pom maven projects in eclipse.
What eventually solved it for me was just going into that particular project's Properties > Builders and unchecking Maven Project Builder (but keeping the Java Builder checked so that it would still auto-build when code changed). I just ignored the warning about this being an "advanced operation" and possibly having "many side-effects" - I figured it couldn't be any more annoying than that constant build-refresh cycle. I'm still not sure what the cause of this loop was, but that stopped it for me. And I haven't had any problems since.

I actually solved the problem that was caused by the jaxb plugin. If the forceRegenerate is set to true you will get the build loop in eclipse (Kepler in my case).
Verify that you have forceRegenerate set to false in your maven-jaxb-plugin.
<configuration>
<forceRegenerate>false</forceRegenerate>
</configuration>

M2e, even in eclipse mars, seems to like infinite building.
In my case, no such thing as repeated build commands, as listed bellow.
The only thing that seems to work when the project tree is gigantic is:
open eclipse
Disable build automatically as soon as you open eclipse
refresh the workspace and trigger manual a Crtl+B or a build all.
Once eclipse is satisfied that it build the full project tree ... better have four core machine or you're gonna be waiting a while, you can finely put the build automatically option active. Eclipse seems not to go in a building spree after that. It will still go for a while scanning some folders, but activating the build automatically - once you've built it all before - is much faster than a new build all, and finally, eclipse becomes stable stops building infinitely.
Otherwise, you're stuck with the deprecated mvn eclipse:eclipse ...
and have to abandon the use of maven commands from within eclipse echosystem. M2e seems to have a really gigantic hard time cooperating with the beast.
I still use m2e, but must say it is 100 times more difficult to swallow m2e than maven integration in netbeans. On the otherhand, eclipse is much faster for very large code base. Pick your poison, you'll always get bitten.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>rootPom</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

The problem can be a code generating plugin like the openapi-generator-maven-plugin or the protoc-jar-maven-plugin. Such plugins are generating code that retriggers the eclipse compilation. A solution to prevent this behavior could be to disable the plugin for the Eclipse "Maven Project Builder". This can be done by adding an entry to the pom.xml like described here: https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<!-- Add plugin execution configuration here -->
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Such Plugin configuration could look like similar to the following example:
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<versionRange>[0.0,)</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
Alternatively such settings could be done globally for a eclipse workspace: Window > Preferences > Maven > Lifecycle Mappings.
More about this topic can be read here: https://www.benchresources.net/eclipse-maven-plugin-execution-not-covered-by-lifecycle-configuration/

This issue generally also comes when maven unable to delete some file may that is having too long name. So you can manually go to your target folder and clean it and restart eclipse.

it some times worked for me when i change my JAVA_HOME to a new location

I did something similar to Amos M. Carpenter response (https://stackoverflow.com/a/28713259/4470352)
But also I created a new custom builder with the following configuration:
Choose configuration type -> Program
Location (text box) <= D:\apache-maven-3.3.9\bin\mvn.cmd (my custom maven)
Working Directory (text box) <= ${workspace_loc:/project}
Arguments (text area)
<= clean compile test-DproxySet=true -DproxyHost=a.proxy.host -DproxyPort=8080
This compiles me the project with no progress bar, but i can see the progress in text console.
The problem in my case is that every time I compile that project, I download a WSDL and I need to provide proxy configuration. When maven project builder plug-in tries to compile my project, fails and starts again in a loop.
I have tried to setup it into settings.xml maven configuration file, but doesn't work for me, and providing proxy configuration in command line works.
So creating that custom builder does the job and is a new approach.
I hope it to helps you.

I have configured the java environment variable properly (i.e., JAVA_HOME).
Also added the jdk path to the environment variable path, in my case path is C:\Program Files\Java\jdk1.8.0_101\bin.
Also I added path to JDK home in "Installed JREs" preference in Eclipse.
Not sure which one of this resolved the issue, I don't see auto build happening now.
After this, I created a new maven project. Which was set to use the 1.7 by default, this project too resulted in endless loop. But 1.7 is not configured in eclipse. Updating the project properties to use the java version available in my eclipse has resolved the issue.

Eclipse on my workstation hangs every time I try to update maven project. The issue is not resolved even after trying a lot of resolutions/workarounds suggested by community. The only thing that works for me is to run mvn clean and install commands from command prompt. I end the task in task manager, run mvn commands and then re-launch eclipse. Running clean build after re-launching eclipse works fine.

I linked some files in eclipse but the source file was missing (deleted in the meantime). This caused eclipse to restart the build. Deleting the broken link solved the problem.

Delete project from eclipse(not from disk).
And import as "General>Existing Projects into Workspace"

This was happening to me after a project I cloned from GitHub changed its structure to multi-module Maven project. Since some eclipse-specific files were in .gitignore, doing git pull kept the originals even after I removed the old project from Eclipse and re-imported it as new with submodules. This apparently caused some chaos leading to the issue.
Nuking the project directory and re-cloning the project resolved the issue.

Eclipse -> Preferences -> Maven -> Installations
Remove additional installation and using EMBEDDED helped me.
The trigger was, that I wanted to have a separated maven setup for
SLF4J: Class path contains multiple SLF4J bindings.

In my case, I was working with react so running node using frontend plugin. If node is running then it stucks on Invoking 'Maven Project Builder'. I closed node and invoking was completed asap. Node instance running in eclipse was creating issue. I am using windows so going into task manager I closed node instances like shown in image and it works fine. You can check if there is any instance under eclipse which is causing issue.

I opened my module's .project file. There were two redundant entries and deleting one helped
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>

I had the same problem. It turns out that I was running Eclipse with the pipe (|) operator, running another process in parallel. The other process was jamming my Eclipse thread. Once I shut down the other process, Eclipse worked fine.

Related

What do I need for autocomplete and ctrl+click to work in eclipse after importing a project from Perforce and converting it to a maven project?

Currently I have perforce that I am importing my project into eclipse from. After I import my project into eclipse I right click on the project go to configure and convert to maven project. After doing all of this I do NOT have autocomplete for the code working and I do NOT have ctrl+click working.
System Specs:
OS: Windows 7 x64
RAM: 8gb
CPU: Intel core i5
HDD: 128gb SDD
Eclipse Version: Juno 4.2 JavaEE
Maven m2e Version: 1.1.0
Perforce Version: 2012.2.486944
Attempts at a Fix
I have noticed that when I right click on my project and look to go to Java Build Path it does not exist.
Under my right click menu properties and under builders I only have "Maven Project Builder"
I have tried to add the proper <buildCommand> for the java builder and the proper <natures> in the .project file. This does NOT fix my issue but does add the Java Build Path I couldn't see in 1. (below is my unaltered .project file)
I have navigated to the .metadata>.plugins and deleted the org.eclipse.jdt.core to eclipse rebuild its indices.
Error Received when trying ctrl+click autocomplete or a right click>References>Workspace
The resource is not on the build path of a Java project
.project file
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>project</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
Is there something simple that I have overlooked, or a step that I forgot to do? Any help regarding this issue would be great.
(*I have searched though issues relating to the ctrl+click and the autocomplete but none of the solutions that I have found have helped and none seem to match the eclipse+perforce+maven issue, but sorry in advance if this topic was covered in a different post)
Alright here is what I did and found out.
I started over with a new copy of eclipse 4.2 EE and redownloaded all of the plugins that I needed: m2e and perforce
If you have a flat Maven Project
Import the project from perforce, right click on the project>configure>Convert to Maven Project
Converting the flat project to a Maven Project indexed everything allowing for the ctrl+click/ctrl+space functionality
If you have a multi module Maven Project
Check out the project using the perforce plugin into your workspace
Import said project as an Existing Maven Project
Eclipse/Maven will automatically find all of the poms underneath the parent directory and build/index your workspace
After that same as above the ctrl+click/ctrl+space functionality should work
My oversight was that the project I was having issues with I did not realize was a multi module maven project and importing it from perforce and trying to convert the parent folder to a maven project did not cause maven to look at all of the poms in the parent's sub-directories. Hope this helps anyone else having this issue.
The way I use Perforce+Maven+Eclipse is to first import my projects as Maven first, and then later right-click the project > Team > Share Project by linking it against my perforce repository. I find that Eclipse doesn't properly manage projects with Maven if I don't directly import it as a Maven project from the start.

Eclipse Problems View doesn't show Errors

[Note: There is another thread about this problem but it did not answer the question.]
For one specific project in Eclipse, the problems view does not show errors. It shows warnings but it does not show errors. The other projects do show errors (and everything else). For that problematic project, I can see the red squiggly error line in the files. However, the directory structure does not show an error icon and the error is not populated in the Problems View.
Any ideas?
I want to post my story here if Google brings you to this question.
Somehow, "Project->Build Automatically" got turned off.
Turning it back on produces correct errors list.
I've tested that this is the case as far as Ganymede ( at the point of writing this post I am running Indigo )
For anyone else who is having this problem, I have found the answer:
Make sure that Eclipse recognizes your project as a Java project. Specifically, under Project Properties ensure that you have a Java Builder that is checked.
That way, your project will be built and you will see errors in the Problems view.
This was my problem:
http://solveme.wordpress.com/2009/01/06/eclipse-project-missing-default-java-builder/
You'll likely need to change the filter on the Problems view to see the errors. There's a downward pointing arrow in the upper right corner of the panel. Click it -> Configure Contents..., and in the Scope make sure "On any element" is selected.
I had the problem where in the red cross icon by the file name did not appear. I tried all possibilities described on this question. However, the root cause in my case was, I deleted a jar file from SVN. So the java file using the imports from this jar had errors. Surprisingly that didn't show up.
Looking at the build path, I found under Java Build Path -> Libraries -> jar (missing).
Having removed it from the build path, the red icon next to the file showed up !!
Excruciating it was to find this error and wasting so much time, I wonder why this icon does not show up nor does Problem view report it.
I googled this question having same problem, my solution was simply Project -> Clean.
I checked the .classpath file of the Eclipse project. It had incorrect value of src so it was pointing to the wrong source of Java files.
My files incorrect entry:
<classpathentry kind="src" path="src"/>
I changed it to the correct entry:
<classpathentry kind="src" path="source/java"/>
Now it is working.
I'm guessing that the build path for that project is lacking a core library. E.g. if it's a Java project there may not be a JRE/JDK assigned to it.
For a Java project, check this: Properties > Java Build Path > Libraries (this may differ depending on the version of Eclipse, I'm using 3.2.1 at the moment)
There should be a JRE or JDK listed here.
Here is the solution I use when the red icons do not appear on the project tree to highlight errors in our project files from Eclipse (Windows version).
Make sure Eclipse is running on the correct JVM. By default, it will use the latest JRE classpath stored in a registry. If you need to run Eclipse from a JDK instead of JRE, you need to tell Eclipse. So, add the -vm option at the top of the eclipse.ini to refer to our preferred JDK as follows:
-vm
C:\Program Files\Java\jdk1.7.0_21/bin/javaw.exe
Remember to change this when you are upgrading your JRE/JDK.
However, we may encounter issue with Maven complaining about tools.jar in a project's pom.xml. If Eclipse is running on Java JRE instead of JDK, it can be a problem to some Maven plugins like maven-bundle-plugin that still rely on tools.jar which only exists on JDK, causing it to complain. Don't worry about it if your still prefer to run Eclipse using JRE as you can put this entry inside your project's pom.xml to explicitly refer to the right tools.jar:
<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>windows_profile</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>osx_profile</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
</profile>
</profiles>
My problem was that I had a project that I had not edited in a while, so it was linking on a version of the jre that I no longer had on my system. I went to the project properties --> java build path and deleted the reference to the outdated jre.
I am a newbie to STS, and I had a similar problem. Errors weren't showing up until I saved the file. I discovered it was because I was using the Text Editor, instead of the Java Editor.
I had this mysterious problem in my new installation of Spring Tool Suite 4.
Then I realized that most of the columns in the problems view had been reduced to zero width for some weird reason.
So I just had to drag in the columns from the left and everything appeared.

Problems by import of a multiple modules maven 2 project into eclipse workspace

I was wondering if someone has experienced the same problem as me and can help me.
I have a maven project which contains 6 modules. Some of modules are depending on each other. The project is written in Java and builds to jars, wars and aar. I've been trying to import it to Eclipse with the m2eclipse plug-in. It seems to work fine until the project builds. During the build process I get hundreds of errors complaining about missing Java files which are generated. As I found out eclipse can't recognize that some of generated packages should be interpreted as source code. I don't realy know what to do with it as I spent a lot of time already trying to solve this issue. The project is building fine with command line. My target is to debug the whole project on Tomcat server that's why I want to use eclipse as it has a pretty good integration with Tomcat.
Every help would be greatly appreciated.
Thank you!
As documented in the Why generated source folders are not added to classpath entry of the FAQ:
Maven plugins used to generate source
code from resources or other sources
can register additional source folders
to Maven project during the build.
Usually such plugins are bound to
process-resources (or
process-test-resources) build phase
(for example jaxb, modello or xdoclet
plugins). This means that to get those
source folders for generated sources,
we have to run corresponding Maven
build phase.
Not all projects using generated
sources, so for performance reasons,
m2eclipse does not run any Maven goals
by default on project import. This can
be changed in the Maven settings in
"Window > Preferences... > Maven >
Goals to run on project import" (e.g.
you can specify "process-resources"
build phase or specific plugins in
that field).
Alternatively you can run "Maven >
Update project configuration" action
from the project popup menu, which is
configured to run "process-resources"
by default and it can be also changed
on the same preference page.
So either add the goal to which the source generation process is bound to the list of goals to run on import or generate sources by running maven and update the project configuration.
Try using mvn eclipse:eclipse
Under the project where you have additionally generated source. When this is generated by maven it is normally under target folder.
Therefor eclipse:eclipse will recognize this and add as a source folder.
Rembember to refresh the project after this.
Use build-helper-maven-plugin (sample bellow) to tell Eclipse to add a generated folder to the build path :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/cxf</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Add this in the pom of each project that generates sources...

maven - use generics in a eclipse's maven project

I have a maven website project generated by archtype plugin with eclipse IDE. The problem is when i need to use generics or any thing of java 5 or 6, i changed the project compiler to 1.6 and i got a error mark on the project icon in the package explorer but everything is fine. I think it is cause by maven but I dont know how to get rid of it.
Thank you
Don't forget to configure the maven-compiler-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- Lock down plugin version for build reproducibility -->
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
I second with what Mike has said.
Even after changing the entries in pom, i was still getting the compiler error.
and it worked onlt after deleting the project and importing it again in the workspace
You need to make sure Eclipse is compiling with the Java 1.6.
Go to your project-specific settings: Project > Properties. Type "Java Compiler" in the text box to the left.
Ensure that all those drop-downs under "JDK Compliance" are set to 1.6. Otherwise check the box to 'Enable project-specific settings' and manually set them to JDK 1.6.
You may also want to enforce this through Windows > Properties, Java > Compiler, Compiler compliance level > 1.6, for global default settings.
Also make sure that the version of the JDK on your build path is the one you want. Hope this helps.
This is kludgy, but I've run into similar issues and worked around them by deleting the project (and not the sources obviously). Then I would import the maven project into my workspace.
m2eclipse ends up resolving the project again and sets up the project correctly.

Get source jar files attached to Eclipse for Maven-managed dependencies

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?
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.
This is achieved by going into Window > Preferences > Maven and checking the "Download Artifact Sources" and "Download Artifact JavaDoc" options.
mvn eclipse:eclipse -DdownloadSources=true
or
mvn eclipse:eclipse -DdownloadJavadocs=true
or you can add both flags, as Spencer K points out.
Additionally, the =true portion is not required, so you can use
mvn eclipse:eclipse -DdownloadSources -DdownloadJavadocs
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>
</plugins>
</build>
...
</project>
I prefer not to put source/Javadoc download settings into the project pom.xml file as I feel these are user preferences, not project properties. Instead, I place them in a profile in my settings.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>sources-and-javadocs</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>sources-and-javadocs</activeProfile>
</activeProfiles>
</settings>
Right click on project -> maven -> download sources
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.
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)
There is also a similiar question that answers this and includes example pom settings.
I tried windows->pref..->Maven But it was not working out. Hence I created a new class path with command mvn eclipse:eclipse -DdownloadSources=true and refreshed the workspace once. voila.. Sources were attached.
Source jar's entry is available in class path. Hence new build solved the problem...
in my version of Eclipse helios with m2Eclipse there is no
window --> maven --> Download Artifact Sources (select check)
Under window is only "new window", "new editor" "open perspective" etc.
If you right click on your project, then chose maven--> download sources
Nothing happens. no sources get downloaded, no pom files get updated, no window pops up asking which sources.
Doing mvn xxx outside of eclipse is dangerous - some commands dont work with m2ecilpse - I did that once and lost the entire project, had to reinstall eclipse and start from scratch.
Im still looking for a way to get ecilpse and maven to find and use the source of external jars like servlet-api.
Changing pom for maven-eclipse-plugin to include source/javadoc just apply for new dependencies being added to pom. If we need to apply for existing dependencies, we must run mvn dependency:sources. I checked this.
Checking download source/javadoc in Eclipse-Maven preference, sometimes is not enough. In the event maven failed to download them for some reason (a network blackout?), maven creates some *.lastUpdated files, then will never download again. My empirical solution was to delete the artifact directory from .m2/repository, and restart the eclipse workspace with download source/javadoc checked and update projects at startup checked as well.
After the workspace has been restarted, maybe some projects can be marked in error, while eclipse progress is downloading, then any error will be cleared.
Maybe this procedure is not so "scientific", but for me did succeded.
I've added the pom configuration to the maven-eclipse plugin to download source and javadocs, but I figure/hope that will happen for new dependencies, not existing ones.
For existing dependencies, I browsed in package explorer down to the "Maven Dependencies" and right-clicked on commons-lang-2.5.jar, selected Maven | Download Sources and... nothing appeared to happen (no progress bar or indication that it was doing anything). It did, however, download as I'm able to jump to source in commons-lang now.
overthink suggested using the setup in the pom:
<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>
...
First i thought this still won't attach the javadoc and sources (as i tried unsuccessfully with that -DdownloadSources option before).
But surprise - the .classpath file IS getting its sources and javadoc attached when using the POM variant!
For Indigo (and probably Helios) the checkboxes mentioned above are located here:
Window -> Preferences -> Maven
I had a similar problem, and the solution that worked best for me was to include the source in the same jar as the compiled code (so a given directory in the jar would include both Foo.java and Foo.class). Eclipse automatically associates the source with the compiled code, and automatically provides the JavaDoc from the source. Obviously, that's only helpful if you control the artifact.
After Setting the Properties either at Project Level or User Properties level,
Please do a Maven -> Update Project (Force Update). It downloads the sources
A Small addition to the answer, if your project is not a maven project still you can get the source code of the jars, by using this plugin provided in eclipse
Java Source Attacher