Adding Javadoc for dependencies in an Eclipse project

If you use external dependencies or libraries in an Eclipse project and wanted to link up the Javadocs so you can view them in Eclipse by hovering over a class or method, this tidbit may interest you.

For instance, I’ve added a new dependency to my project but when I go to use it’s methods, in the Javadoc pane I get nothing or it says:

 This element neither has attached source nor attached Javadoc and hence no Javadoc could be found.

Previously, I had to either find the Javadoc online, or build it myself and bookmark it in my browser. This means flipping between applications when I want to read up, and if it was online, what if a net connection isn’t available?

So, you can link up each dependency in your project to it’s corresponding Javadoc and then just click on a method or class and get all the info you need right there.

Here’s how:

1. Get the the Javadoc or build it from source, hopefully as easy as just issuing:

 mvn javadoc:javadoc

if the source uses Maven to build. It will then be located in the target/site/apidocs directory.

2. Put the Javadoc somewhere. I keep mine in a Javadocs folder. Tricky.

3. In Eclipse, click your project, then Build Path > Configure Build Path…

4. Find your dependency in the list, or add a new one.

5. Click the triangle next to the dependency to expand a list of options for each. One is Javadoc location. Highlight this, click Edit and browse for your Javadoc. Click OK and you are done.

Now you can hover over methods from that dependency and get the full Javadoc right there in Eclipse.

Note: There are other methods to do this. If you project uses Maven, you can issue:

mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true

to pull it all into your local Maven repo, however I haven’t found this to work for dependencies that are inherited. I also like to keep my Javadocs in a separate location as I am regularly cleaning out my Maven repo.


One thought on “Adding Javadoc for dependencies in an Eclipse project

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s