How to reference javadocs to dependencies in Maven's eclipse plugin when javadoc not attached to dependency

JavaEclipseMaven 2

Java Problem Overview


I use Eclipse, Maven, and Java in my development. I use Maven to download dependencies (jar files and javadoc when available) and Maven's eclipse plug-in to generate the .project and .classpath files for Eclipse. When the dependency downloaded does not have attached javadoc I manually add a link for the javadoc in the .classpath file so that I can see the javadoc for the dependency in Eclipse. Then when I run Maven's eclipse plugin to regenerate the .classpath file it of course wipes out that change.

Is there a way to configure Maven's eclipse plug-in to automatically add classpath attributes for javadoc when running Maven's eclipse plug-in?

I'm only interested in answers where the javadoc and/or sources are not provided for the dependency in the maven repository, which is the case most often for me. Using downloadSources and/or downloadJavadocs properties won't help this problem.

Java Solutions


Solution 1 - Java

From the Maven Eclipse Plugin FAQ > The following example shows how to do > this in the command-line: > > mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true > > or in your pom.xml: > > > [...] > > [...] > > [...] > > org.apache.maven.plugins > maven-eclipse-plugin > > true > true > > > [...] > > [...] > > [...] >

Solution 2 - Java

I'm running STS 2.8.1 which is basically eclipse + spring tools; In an existing maven project, I right clicked on the project -> maven -> Download Sources and Download JavaDocs

Solution 3 - Java

As mentioned in How to download sources and javadoc artifacts with Maven Eclipse plugin from other repository?, you can do this:

In Eclipse go to Windows-> Preferences-> Maven. Check the box that says "Download Artifact Javadoc." That has worked well for me.

Maven Preferences

Solution 4 - Java

You might consider just avoiding this problem completely by installing the javadoc jar into your local repository manually using the install-file goal and passing in the -Dclassifier=javadoc option. Once you do that the .classpath that mvn generates should be correct.

If you use a remote repo as a proxy to central you could also deploy the javadocs to that repo and then everyone else who uses that proxy will now get the javadocs automatically as well.

Solution 5 - Java

Generally Javadocs are not primarily used as dependency . Because these are neither required at compile nor runtime. It’s just to help the developer while developing or debugging.

Assuming using the java IDE Eclipse we can use the java docs as referenced. Following are the approaches we can associate the javadocs/sources with the respective jars.

1. If it’s non-maven project :

Download the javadocs jar or zipped file, whatever available and placed it in some directory. Right click on the application project in the IDE Eclipse, click Properties and choose Java Build Path then select tab Libraries under the Java Build Path. Now expand the jar you want to link with java docs/source. Select the Javadoc location link and click on Edit button, a new window appears where we need to choose the javadocs jar path. Click OK and we have linked the javadoc/source with the respective jars.

enter image description here

2. If it’s a maven project

If we are using the Maven project then go to jar files under the Maven dependency under the project in Project Explorer view as shown below. Now right click on the jar file you want to add the Javadoc/source,  choose Maven then click on Javadoc or Source you want to link with the project. Now IDE will automatically download the required javadoc/source and will link it with the respective jar in the project.

enter image description here

You can verify this by right click on the project in the IDE and click on Java Build Path and select the Libraries tab under the Java Build Path and then expand the desired jar, here when you click the Edit button you will see the linked path of the Javadoc/Source with the respective jar as shown below in the image.

enter image description here

3. If it’s Maven project and we are setting the default behavior:

Eclipse will aquatically download the javadoc/source along with the main required jar at the starting. By default setting instruction to Maven to download the Javadoc/sources for all the jars linked in the project.

Click Windows – preferences – select Maven and click the checkbox Download Artifact Javadoc as shown below

enter image description here

Now click on apply and save it and now when you create new Maven project , by default the Javadocs will get downloaded and linked with all the dependent jars in the project.
You can verify by right click on the project and Properties and under Java Build path can see the javadocs are linked with all the jars as shown below.

enter image description here

If your project is Maven project then It’s always best to use 2nd approach because by using this approach the IDE and Maven, takes care of downloading the correct version of the Javadoc/source and linked it with the relative jar as well.

Approach 3rd is bit costly because the javadoc/sources will be downloaded for-all the dependent jars, may be you are not interested for javadocs/sources for all the dependent jars.

Solution 6 - Java

Would having the sources for the dependency help? You can tell the eclipse plugin to download those (and refer to them in the .classpath) with -DdownloadSources=true

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohn in MDView Question on Stackoverflow
Solution 1 - JavaddimitrovView Answer on Stackoverflow
Solution 2 - JavaluckyphilView Answer on Stackoverflow
Solution 3 - JavaPhilippeView Answer on Stackoverflow
Solution 4 - JavaMike DeckView Answer on Stackoverflow
Solution 5 - JavaKulDeepView Answer on Stackoverflow
Solution 6 - Javamatt bView Answer on Stackoverflow