Javadoc指向Oracle API文档的链接失效,如何修复?
Hey there, let's sort out this broken link issue with Javadoc's -link option. The old Oracle URL you're using (http://docs.oracle.com/javase/8/docs/api/) is likely failing because of either Oracle updating their documentation routing, or the unsecure HTTP protocol being redirected to HTTPS in a way Javadoc can't handle automatically. Here are a few solid fixes:
1. Switch to the HTTPS Version of Oracle's Official Path
First, update the URL to use HTTPS and the current official path. Try this in your Javadoc command:
-link https://docs.oracle.com/javase/8/docs/api/
If that still doesn't work (sometimes Oracle's regional redirects cause hiccups), use the fully qualified internationalized path instead:
-link https://docs.oracle.com/en/java/javase/8/docs/api/
This should resolve most cases where the old HTTP link was getting blocked or redirected improperly.
2. Use a Trusted OpenJDK Documentation Mirror
If Oracle's links are still giving you trouble—whether due to access restrictions or redirect loops—you can use a reliable mirror maintained by the Eclipse Adoptium project. For Java 8, use this:
-link https://docs.adoptium.net/jdk8/docs/api/
This mirror is stable, doesn't require any license agreements to access, and stays up to date with the official Java 8 API docs.
3. Fix Compatibility with Newer JDK Tools
If you're using a newer JDK (like 11 or later) to generate docs for Java 8 code, newer Javadoc versions might have stricter HTTPS handling. If you run into SSL-related errors, add a flag to enforce a compatible TLS version:
javadoc -J-Dhttps.protocols=TLSv1.2 -link https://docs.oracle.com/javase/8/docs/api/ [your other Javadoc options]
This ensures the Javadoc tool can establish a secure connection to the documentation server without issues.
4. Host the API Docs Locally (For Offline Reliability)
If you need consistent, offline access to working links, download the Java 8 API docs ZIP from Oracle's website, extract it to a local directory on your machine, then link to that local path:
-link file:///path/to/your/extracted/javadoc/api/
Replace /path/to/your/extracted/javadoc/api/ with the actual file path on your system. This way, your generated docs will always have working links, no matter what's happening with external servers.
内容的提问来源于stack exchange,提问作者Matthew Cline

