Faizan
Faizan

Reputation: 309

Adding Libraries to Intellij IDEA projects shows sources not found

I have added the Javax.mail library to my project, and added the jar files as Libraries and included the dependencies as well but still it displays "Sources not found" in the Javax.mail classes and wants me to attach sources. Help Plz

I'm not using Maven

Upvotes: 2

Views: 2380

Answers (1)

Javaru
Javaru

Reputation: 31976

When you add a library to IntelliJ IDEA, at a minimum you need to attach the JAR (or directory) containing the compiled classes (i.e. the binaries). You then can optionally add either the source code, the javadoc, or both. Javadoc can be added as a JAR file, a ZIP file, a directory, or as a URL. Source code can be added via a JAR file, a ZIP file, or a directory.

Adding either the Javadoc or the source file will allow you to see the libraries Javadoc documentation via the "View Quick Documentation" action (Ctrl+Q / J or View > Quick Documentation from the menu). Since the source code has the Javadoc source, IDEA can pull the Javadoc from it.

An additional added advantage of having the source code attached is that you can actually view the source code (via various actions like quick definition lookup Ctrl+Shift+I / Space or via the view menu, or the go to implementation or declaration actions).

With third party libraries, not all of them will have Javadoc and/or source code available. Some will have one or the other, some both, and some neither. Sometimes,you have to go hunting for the source code or Javadoc. The two best places to look are the project's home page and the Maven Central Repository (http://search.maven.org/). Even if you are not using maven to build your project, you can find and download binary, source, and javadoc for a lot of projects/libraries there making it a good resource.

If you go the the Maven Central, and do a search for javax mail, in the search results listing will be the javax.mail library. If you click the all link for it, you will get a listing of all the versions of the javax mail API available in maven central. Some have Javadoc and sources available (especially the most recent ones), some only sources, and some neither (mostly older releases).

So in this case, we can find the source, download it, and attach it. However, in some cases you will not be able to. Especially for propitiatory (i.e. non-open-source) software that does not release the source. That's OK. You simple loose the functionality to be able to view the source of a class. You know that and can ignore the warning.

Upvotes: 2

Related Questions