I am trying to link into some Javadocs hosted at javadoc.io (specifically, PowerMock's Javadocs) using the @link
option. I have tried to add the URL to PowerMock's Javadocs to my -link
flag, but can't get Javadoc to recognize it. I am using external links to other Javadocs just fine (e.g. Guava, Java SE 7) with Gradle as my build system. I have tried the following options:
-link http://static.javadoc.io/org.powermock/powermock-core/1.6.3/
^ I have confirmed that there is a package-list
file in this directory
-link http://static.javadoc.io/org.powermock/powermock-core/
-link http://javadoc.io/doc/org.powermock/powermock-core/1.6.3/
-link http://javadoc.io/doc/org.powermock/powermock-core/
All of these result in the following error (URL changed accordingly):
javadoc: warning - Error fetching URL: http://static.javadoc.io/org.powermock/powermock-core/1.6.3/
Does anyone have advice on how to make this work?
As far as I can tell this is some sort of javadoc.io specific problem, though likely a usage issue on my end – for example I am currently using -link http://junit.org/javadoc/latest/
without issue, but -link http://static.javadoc.io/junit/junit/4.12/
doesn't work.
Best Answer
From the command line, use an argument like
-J-Dhttp.agent=javadoc
.In Maven, use something like:
<additionalJOption>-J-Dhttp.agent=maven-javadoc-plugin-${pom.name}</additionalJOption>
The background: As Danilo Pianini suggests in another answer, the problem is the
User-Agent
header. However, the problem isn't an emptyUser-Agent
; it's the default JavaUser-Agent
, which looks something like "Java/1.8.0_112
":So the fix is to tell Javadoc to use a different
User-Agent
. Java won't let you omit theUser-Agent
, so you'll have to provide a value, which Java will prepend to its default agent.As best I can tell, the blocking of Javadoc isn't intentional: Javadoc just (probably unwisely) uses the default Java
User-Agent
, and the content delivery network thatjavadoc.io
uses blocks that by default.(One more note about Maven: Everything works fine with
-link
. It also works fine with-linkoffline
if you download thepackage-list
file and tell Javadoc to read it from disk. However, if you use-linkoffline
but tell Javadoc to fetchpackage-list
from thejavadoc.io
URL (this is an unusual thing to do), it may fail. The problem: Maven tries to pre-validate thepackage-list
file but, under some versions of Java, fails because it rejects the SSL certificate ofjavadoc.io
, a certificate that Javadoc itself accepts.)(Oh, and it appears to be important to use a URL specifically from
static.javadoc.io
, notjavadoc.io
. Also, I would recommendhttps
, nothttp
, in casehttp://static.javadoc.io
someday starts issuing redirects tohttps://static.javadoc.io
, as Javadoc currently doesn't handle such redirects. Also,https
is a good thing :))