使用Javadoc -link选项链接到javadoc.io [英] Linking to javadoc.io using Javadoc -link option

查看:146
本文介绍了使用Javadoc -link选项链接到javadoc.io的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用@link选项链接到托管在javadoc.io上的某些Javadocs(特别是PowerMock的Javadocs).我试图将PowerMock的Javadocs的URL添加到我的-link标志,但是无法使Javadoc识别它.我正在使用Gradle作为构建系统来很好地连接到其他Javadocs的外部链接(例如Guava,Java SE 7).我尝试了以下选项:

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/

^我已经确认此目录中有一个package-list文件

^ 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?

据我所知,这是某种javadoc.io特定的问题,尽管可能是我的使用方面的问题-例如,我当前正在使用-link http://junit.org/javadoc/latest/却没有问题,但是-link http://static.javadoc.io/junit/junit/4.12/无效.

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.

推荐答案

在命令行中,使用类似-J-Dhttp.agent=javadoc的参数.

From the command line, use an argument like -J-Dhttp.agent=javadoc.

在Maven中,使用类似以下内容的

In Maven, use something like:

<additionalJOption>-J-Dhttp.agent=maven-javadoc-plugin-${pom‌​.name}</additionalJO‌​ption>

背景:正如Danilo Pianini在另一个答案中所建议的那样,问题出在User-Agent标头.但是,问题不是 empty User-Agent这是默认的Java User-Agent ,看起来像":

The background: As Danilo Pianini suggests in another answer, the problem is the User-Agent header. However, the problem isn't an empty User-Agent; it's the default Java User-Agent, which looks something like "Java/1.8.0_112":

$ URL=https://static.javadoc.io/org.checkerframework/checker-qual/2.2.2/package-list

# default Java User-Agent:
$ wget -U Java/1.8.0_112 "$URL" 2>&1 | grep response
HTTP request sent, awaiting response... 403 Forbidden

# no User-Agent:
$ wget -U '' "$URL" 2>&1 | grep response
HTTP request sent, awaiting response... 200 OK

# custom User-Agent:
$ wget -U javadoc "$URL" 2>&1 | grep response
HTTP request sent, awaiting response... 200 OK

因此解决方法是告诉Javadoc使用其他User-Agent. Java不允许您省略User-Agent,因此您必须提供一个值,该值将Java附加到其默认代理中.

So the fix is to tell Javadoc to use a different User-Agent. Java won't let you omit the User-Agent, so you'll have to provide a value, which Java will prepend to its default agent.

据我所知,阻止Javadoc并不是故意的:Javadoc只是(可能是不明智的)使用默认的Java User-Agent,而内容交付网络中的javadoc.io使用默认情况下的块.

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 that javadoc.io uses blocks that by default.

(有关Maven的另一条注释:-link一切正常.如果下载package-list文件并告诉Javadoc从磁盘读取它,则它也与-linkoffline正常工作.但是,如果使用,但告诉Javadoc从javadoc.io URL中获取package-list(这是不寻常的事情),

(One more note about Maven: Everything works fine with -link. It also works fine with -linkoffline if you download the package-list file and tell Javadoc to read it from disk. However, if you use -linkoffline but tell Javadoc to fetch package-list from the javadoc.io URL (this is an unusual thing to do), it may fail. The problem: Maven tries to pre-validate the package-list file but, under some versions of Java, fails because it rejects the SSL certificate of javadoc.io, a certificate that Javadoc itself accepts.)

(哦,使用从static.javadoc.io而不是javadoc.io专门指定的URL似乎很重要.此外,我建议使用https而不是http,以防万一http://static.javadoc.io有一天开始发布重定向到https://static.javadoc.io,因为Javadoc 目前无法处理此类重定向.此外, https是一件好事:))

(Oh, and it appears to be important to use a URL specifically from static.javadoc.io, not javadoc.io. Also, I would recommend https, not http, in case http://static.javadoc.io someday starts issuing redirects to https://static.javadoc.io, as Javadoc currently doesn't handle such redirects. Also, https is a good thing :))

这篇关于使用Javadoc -link选项链接到javadoc.io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆