[笔记&轮子]java源码 生成本地javadoc api文档

在用Eclipse写java代码时候,有时候因为不知道一个java函数的作用,会通过把鼠移动到java函数上,如果它有javadoc的相关内容就会显示出来。但是并非所有java代码都有javadoc;即使安装了javadoc,在eclipse中如果不进行设定,也可能无法使用。

我在win7下安装的是javase的jdk,发现eclipse中默认的javadoc路径是http://download.oracle.com/javase/7/docs/api/,显然这是一个在线资源,问题是网络总是不稳定的,有时候看不到对应的文档内容。so,what should we do?and what can we do?!

一个显而易见的解决方法是下载javadoc并在本地安装,然后在eclipse中修改javadoc的路径。但是,为什么要下载javadoc?不是有一个命令也叫javadoc的么?不能用么?在java安装路径下可以找到一个叫src.zip的压缩包,里面是java的源码,而且有注释,应该可以生成javadoc的。到oracle官方上看了一下,发现javase版本的jdk就是不带文档的,而javaee版本的jdk却带文档。好吧,反正我对oracle没有什么好感,对此我只能呵呵。

如何手动生成本地javadoc api文档?对于jdk中的java源码,因为包含太多的包,因此需要统计所有使用到的包,也就是“当前路径下包含java文件的所有文件夹”。ok,因为google不能用,百度出来的结果基本上是没参考价值,唯一有用的一个是分析swf源码的例子,够了。通过获取所有包的路径并存储在一个叫package.txt的文件中,并存储在java源码解压后的路径src下,然后运行cmd,cd到src路径,输入javadoc javadoc -d api @package.txt命令,静候5分钟,文档就会生成完毕!

然后我们也可以通过chrome打开,比如JComponent.html页面:

附:用来获取java源码中所有包含java文件的目录的代码:

package util;

import java.io.File;
import java.util.Vector;

public class SniffDir {
	private String srcDir;
	private Vector<String> vs;
	public SniffDir(){
		srcDir="D:/workspace/src";
		vs=new Vector<String>();
	}
	/**
	 * Sniff函数, 其实就是一个DFS,深度优先搜索
	 * 用来获取src目录下的满足“当前路径下存在.java文件”这一条件的所有文件夹
	 * @param file
	 */
	public void Sniff(File file) {
		//File file=new File(curDir);
		File[] files=file.listFiles();
		int len=files.length;
		boolean ok=false;//表示当前目录下是否有java文件,ok=true表示有并且记录过了。
		for(int i=0; i<len; i++){
			//System.out.println(files[i].toString());
			if(files[i].isDirectory()){
				Sniff(files[i]);
			}else if(files[i].isFile() && !ok){//files[i]为文件(肯定是java文件),并且还没有把当前路径放入向量vs中
				ok=true;
				vs.addElement(file.toString().substring(srcDir.length()+1));
				//System.out.println(files[i].toString());
			}
		}
	}
	String sb=null;
	public void Print(){
		int len=vs.size();
		for(int i=0; i<len; i++){
			sb=vs.get(i);
			sb=sb.replace('\\', '.');
			System.out.println(sb);
		}
	}
	public static void main(String[] args){
		SniffDir sd=new SniffDir();
		sd.Sniff(new File(sd.srcDir));
		sd.Print();
	}
}

获取的结果(存储在package.txt中并放到src目录下即可):

com.sun.corba.se.impl.activation
com.sun.corba.se.impl.copyobject
com.sun.corba.se.impl.corba
com.sun.corba.se.impl.dynamicany
com.sun.corba.se.impl.encoding
com.sun.corba.se.impl.interceptors
com.sun.corba.se.impl.io
com.sun.corba.se.impl.ior
com.sun.corba.se.impl.ior.iiop
com.sun.corba.se.impl.javax.rmi.CORBA
com.sun.corba.se.impl.javax.rmi
com.sun.corba.se.impl.legacy.connection
com.sun.corba.se.impl.logging
com.sun.corba.se.impl.monitoring
com.sun.corba.se.impl.naming.cosnaming
com.sun.corba.se.impl.naming.namingutil
com.sun.corba.se.impl.naming.pcosnaming
com.sun.corba.se.impl.oa
com.sun.corba.se.impl.oa.poa
com.sun.corba.se.impl.oa.toa
com.sun.corba.se.impl.orb
com.sun.corba.se.impl.orbutil
com.sun.corba.se.impl.orbutil.closure
com.sun.corba.se.impl.orbutil.concurrent
com.sun.corba.se.impl.orbutil.fsm
com.sun.corba.se.impl.orbutil.graph
com.sun.corba.se.impl.orbutil.threadpool
com.sun.corba.se.impl.presentation.rmi
com.sun.corba.se.impl.protocol
com.sun.corba.se.impl.protocol.giopmsgheaders
com.sun.corba.se.impl.resolver
com.sun.corba.se.impl.transport
com.sun.corba.se.impl.util
com.sun.corba.se.internal.corba
com.sun.corba.se.internal.CosNaming
com.sun.corba.se.internal.iiop
com.sun.corba.se.internal.Interceptors
com.sun.corba.se.internal.POA
com.sun.corba.se.org.omg.CORBA
com.sun.corba.se.pept.broker
com.sun.corba.se.pept.encoding
com.sun.corba.se.pept.protocol
com.sun.corba.se.pept.transport
com.sun.corba.se.PortableActivationIDL
com.sun.corba.se.PortableActivationIDL.InitialNameServicePackage
com.sun.corba.se.PortableActivationIDL.LocatorPackage
com.sun.corba.se.PortableActivationIDL.RepositoryPackage
com.sun.corba.se.spi.activation
com.sun.corba.se.spi.activation.InitialNameServicePackage
com.sun.corba.se.spi.activation.LocatorPackage
com.sun.corba.se.spi.activation.RepositoryPackage
com.sun.corba.se.spi.copyobject
com.sun.corba.se.spi.encoding
com.sun.corba.se.spi.extension
com.sun.corba.se.spi.ior
com.sun.corba.se.spi.ior.iiop
com.sun.corba.se.spi.legacy.connection
com.sun.corba.se.spi.legacy.interceptor
com.sun.corba.se.spi.logging
com.sun.corba.se.spi.monitoring
com.sun.corba.se.spi.oa
com.sun.corba.se.spi.orb
com.sun.corba.se.spi.orbutil.closure
com.sun.corba.se.spi.orbutil.fsm
com.sun.corba.se.spi.orbutil.proxy
com.sun.corba.se.spi.orbutil.threadpool
com.sun.corba.se.spi.presentation.rmi
com.sun.corba.se.spi.protocol
com.sun.corba.se.spi.resolver
com.sun.corba.se.spi.servicecontext
com.sun.corba.se.spi.transport
com.sun.image.codec.jpeg
com.sun.imageio.plugins.bmp
com.sun.imageio.plugins.common
com.sun.imageio.plugins.gif
com.sun.imageio.plugins.jpeg
com.sun.imageio.plugins.png
com.sun.imageio.plugins.wbmp
com.sun.imageio.spi
com.sun.imageio.stream
com.sun.java.swing
com.sun.java.swing.plaf.gtk
com.sun.java.swing.plaf.motif
com.sun.java.swing.plaf.motif.resources
com.sun.java.swing.plaf.nimbus
com.sun.java.swing.plaf.windows
com.sun.java.swing.plaf.windows.resources
com.sun.javadoc
com.sun.java_cup.internal.runtime
com.sun.jmx.defaults
com.sun.jmx.interceptor
com.sun.jmx.mbeanserver
com.sun.jmx.remote.internal
com.sun.jmx.remote.protocol.iiop
com.sun.jmx.remote.protocol.rmi
com.sun.jmx.remote.security
com.sun.jmx.remote.util
com.sun.jmx.snmp.agent
com.sun.jmx.snmp
com.sun.jmx.snmp.daemon
com.sun.jmx.snmp.defaults
com.sun.jmx.snmp.internal
com.sun.jmx.snmp.IPAcl
com.sun.jmx.snmp.mpm
com.sun.jmx.snmp.tasks
com.sun.jmx.trace
com.sun.mirror.apt
com.sun.mirror.declaration
com.sun.mirror.type
com.sun.mirror.util
com.sun.naming.internal
com.sun.org.apache.bcel.internal.classfile
com.sun.org.apache.bcel.internal
com.sun.org.apache.bcel.internal.generic
com.sun.org.apache.bcel.internal.util
com.sun.org.apache.regexp.internal
com.sun.org.apache.xalan.internal.extensions
com.sun.org.apache.xalan.internal.lib
com.sun.org.apache.xalan.internal.res
com.sun.org.apache.xalan.internal.templates
com.sun.org.apache.xalan.internal.utils
com.sun.org.apache.xalan.internal
com.sun.org.apache.xalan.internal.xslt
com.sun.org.apache.xalan.internal.xsltc.cmdline
com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt
com.sun.org.apache.xalan.internal.xsltc
com.sun.org.apache.xalan.internal.xsltc.compiler
com.sun.org.apache.xalan.internal.xsltc.compiler.util
com.sun.org.apache.xalan.internal.xsltc.dom
com.sun.org.apache.xalan.internal.xsltc.runtime
com.sun.org.apache.xalan.internal.xsltc.runtime.output
com.sun.org.apache.xalan.internal.xsltc.trax
com.sun.org.apache.xalan.internal.xsltc.util
com.sun.org.apache.xerces.internal.dom
com.sun.org.apache.xerces.internal.dom.events
com.sun.org.apache.xerces.internal.impl
com.sun.org.apache.xerces.internal.impl.dtd
com.sun.org.apache.xerces.internal.impl.dtd.models
com.sun.org.apache.xerces.internal.impl.dv
com.sun.org.apache.xerces.internal.impl.dv.dtd
com.sun.org.apache.xerces.internal.impl.dv.util
com.sun.org.apache.xerces.internal.impl.dv.xs
com.sun.org.apache.xerces.internal.impl.io
com.sun.org.apache.xerces.internal.impl.msg
com.sun.org.apache.xerces.internal.impl.validation
com.sun.org.apache.xerces.internal.impl.xpath.regex
com.sun.org.apache.xerces.internal.impl.xpath
com.sun.org.apache.xerces.internal.impl.xs
com.sun.org.apache.xerces.internal.impl.xs.identity
com.sun.org.apache.xerces.internal.impl.xs.models
com.sun.org.apache.xerces.internal.impl.xs.opti
com.sun.org.apache.xerces.internal.impl.xs.traversers
com.sun.org.apache.xerces.internal.impl.xs.util
com.sun.org.apache.xerces.internal.jaxp.datatype
com.sun.org.apache.xerces.internal.jaxp
com.sun.org.apache.xerces.internal.jaxp.validation
com.sun.org.apache.xerces.internal.parsers
com.sun.org.apache.xerces.internal.util
com.sun.org.apache.xerces.internal.utils
com.sun.org.apache.xerces.internal.xinclude
com.sun.org.apache.xerces.internal.xni
com.sun.org.apache.xerces.internal.xni.grammars
com.sun.org.apache.xerces.internal.xni.parser
com.sun.org.apache.xerces.internal.xpointer
com.sun.org.apache.xerces.internal.xs
com.sun.org.apache.xerces.internal.xs.datatypes
com.sun.org.apache.xml.internal.dtm
com.sun.org.apache.xml.internal.dtm.ref
com.sun.org.apache.xml.internal.dtm.ref.dom2dtm
com.sun.org.apache.xml.internal.dtm.ref.sax2dtm
com.sun.org.apache.xml.internal.res
com.sun.org.apache.xml.internal.resolver
com.sun.org.apache.xml.internal.resolver.helpers
com.sun.org.apache.xml.internal.resolver.readers
com.sun.org.apache.xml.internal.resolver.tools
com.sun.org.apache.xml.internal.security.algorithms
com.sun.org.apache.xml.internal.security.algorithms.implementations
com.sun.org.apache.xml.internal.security.c14n
com.sun.org.apache.xml.internal.security.c14n.helper
com.sun.org.apache.xml.internal.security.c14n.implementations
com.sun.org.apache.xml.internal.security.encryption
com.sun.org.apache.xml.internal.security.exceptions
com.sun.org.apache.xml.internal.security
com.sun.org.apache.xml.internal.security.keys.content
com.sun.org.apache.xml.internal.security.keys.content.keyvalues
com.sun.org.apache.xml.internal.security.keys.content.x509
com.sun.org.apache.xml.internal.security.keys
com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations
com.sun.org.apache.xml.internal.security.keys.keyresolver
com.sun.org.apache.xml.internal.security.keys.storage.implementations
com.sun.org.apache.xml.internal.security.keys.storage
com.sun.org.apache.xml.internal.security.signature
com.sun.org.apache.xml.internal.security.transforms
com.sun.org.apache.xml.internal.security.transforms.implementations
com.sun.org.apache.xml.internal.security.transforms.params
com.sun.org.apache.xml.internal.security.utils
com.sun.org.apache.xml.internal.security.utils.resolver.implementations
com.sun.org.apache.xml.internal.security.utils.resolver
com.sun.org.apache.xml.internal.serialize
com.sun.org.apache.xml.internal.serializer
com.sun.org.apache.xml.internal.serializer.utils
com.sun.org.apache.xml.internal.utils
com.sun.org.apache.xml.internal.utils.res
com.sun.org.apache.xpath.internal
com.sun.org.apache.xpath.internal.axes
com.sun.org.apache.xpath.internal.compiler
com.sun.org.apache.xpath.internal.domapi
com.sun.org.apache.xpath.internal.functions
com.sun.org.apache.xpath.internal.jaxp
com.sun.org.apache.xpath.internal.objects
com.sun.org.apache.xpath.internal.operations
com.sun.org.apache.xpath.internal.patterns
com.sun.org.apache.xpath.internal.res
com.sun.security.auth.callback
com.sun.security.auth
com.sun.security.auth.login
com.sun.security.auth.module
com.sun.security.jgss
com.sun.source.tree
com.sun.source.util
java.applet
java.awt
java.awt.color
java.awt.datatransfer
java.awt.dnd
java.awt.dnd.peer
java.awt.event
java.awt.font
java.awt.geom
java.awt.im
java.awt.im.spi
java.awt.image
java.awt.image.renderable
java.awt.peer
java.awt.print
java.beans
java.beans.beancontext
java.io
java.lang
java.lang.annotation
java.lang.instrument
java.lang.invoke
java.lang.management
java.lang.ref
java.lang.reflect
java.math
java.net
java.nio
java.nio.channels
java.nio.channels.spi
java.nio.charset
java.nio.charset.spi
java.nio.file
java.nio.file.attribute
java.nio.file.spi
java.rmi
java.rmi.activation
java.rmi.dgc
java.rmi.registry
java.rmi.server
java.security
java.security.acl
java.security.cert
java.security.interfaces
java.security.spec
java.sql
java.text
java.text.spi
java.util
java.util.concurrent
java.util.concurrent.atomic
java.util.concurrent.locks
java.util.jar
java.util.logging
java.util.prefs
java.util.regex
java.util.spi
java.util.zip
javax.accessibility
javax.annotation
javax.annotation.processing
javax.imageio.event
javax.imageio
javax.imageio.metadata
javax.imageio.plugins.bmp
javax.imageio.plugins.jpeg
javax.imageio.spi
javax.imageio.stream
javax.lang.model.element
javax.lang.model
javax.lang.model.type
javax.lang.model.util
javax.management
javax.management.loading
javax.management.modelmbean
javax.management.monitor
javax.management.openmbean
javax.management.relation
javax.management.remote
javax.management.remote.rmi
javax.management.timer
javax.naming
javax.naming.directory
javax.naming.event
javax.naming.ldap
javax.naming.spi
javax.print.attribute
javax.print.attribute.standard
javax.print
javax.print.event
javax.rmi.CORBA
javax.rmi
javax.rmi.ssl
javax.script
javax.security.auth
javax.security.auth.callback
javax.security.auth.kerberos
javax.security.auth.login
javax.security.auth.spi
javax.security.auth.x500
javax.security.cert
javax.security.sasl
javax.sound.midi
javax.sound.midi.spi
javax.sound.sampled
javax.sound.sampled.spi
javax.sql
javax.sql.rowset
javax.sql.rowset.serial
javax.sql.rowset.spi
javax.swing
javax.swing.border
javax.swing.colorchooser
javax.swing.event
javax.swing.filechooser
javax.swing.plaf
javax.swing.plaf.basic
javax.swing.plaf.metal
javax.swing.plaf.multi
javax.swing.plaf.nimbus
javax.swing.plaf.synth
javax.swing.table
javax.swing.text
javax.swing.text.html
javax.swing.text.html.parser
javax.swing.text.rtf
javax.swing.tree
javax.swing.undo
javax.tools
javax.xml.bind.annotation.adapters
javax.xml.bind.annotation
javax.xml.bind.attachment
javax.xml.bind
javax.xml.bind.helpers
javax.xml.bind.util
javax.xml.crypto
javax.xml.crypto.dom
javax.xml.crypto.dsig
javax.xml.crypto.dsig.dom
javax.xml.crypto.dsig.keyinfo
javax.xml.crypto.dsig.spec
javax.xml.datatype
javax.xml.namespace
javax.xml.parsers
javax.xml.soap
javax.xml.stream
javax.xml.stream.events
javax.xml.stream.util
javax.xml.transform.dom
javax.xml.transform
javax.xml.transform.sax
javax.xml.transform.stax
javax.xml.transform.stream
javax.xml.validation
javax.xml.ws
javax.xml.ws.handler
javax.xml.ws.handler.soap
javax.xml.ws.http
javax.xml.ws.soap
javax.xml.ws.spi
javax.xml.ws.spi.http
javax.xml.ws.wsaddressing
javax.xml
javax.xml.xpath
launcher
org.ietf.jgss
org.omg.CORBA
org.omg.CORBA.DynAnyPackage
org.omg.CORBA.ORBPackage
org.omg.CORBA.portable
org.omg.CORBA.TypeCodePackage
org.omg.CORBA_2_3
org.omg.CORBA_2_3.portable
org.omg.CosNaming
org.omg.CosNaming.NamingContextExtPackage
org.omg.CosNaming.NamingContextPackage
org.omg.Dynamic
org.omg.DynamicAny
org.omg.DynamicAny.DynAnyFactoryPackage
org.omg.DynamicAny.DynAnyPackage
org.omg.IOP
org.omg.IOP.CodecFactoryPackage
org.omg.IOP.CodecPackage
org.omg.Messaging
org.omg.PortableInterceptor
org.omg.PortableInterceptor.ORBInitInfoPackage
org.omg.PortableServer
org.omg.PortableServer.CurrentPackage
org.omg.PortableServer.POAManagerPackage
org.omg.PortableServer.POAPackage
org.omg.PortableServer.portable
org.omg.PortableServer.ServantLocatorPackage
org.omg.SendingContext
org.omg.stub.java.rmi
org.w3c.dom
org.w3c.dom.bootstrap
org.w3c.dom.css
org.w3c.dom.events
org.w3c.dom.html
org.w3c.dom.ls
org.w3c.dom.ranges
org.w3c.dom.stylesheets
org.w3c.dom.traversal
org.w3c.dom.views
org.w3c.dom.xpath
org.xml.sax
org.xml.sax.ext
org.xml.sax.helpers
sunw.io
sunw.util

[笔记&轮子]java源码 生成本地javadoc api文档,布布扣,bubuko.com

时间: 06-27

[笔记&轮子]java源码 生成本地javadoc api文档的相关文章

MultiThread(VS2013 MFC多线程-含源码-含个人逐步实现文档)

原文:http://download.csdn.net/download/jobfind/9559162 MultiThread(VS2013 MFC多线程-含源码-含个人逐步实现文档).rar

使用java源码生成Kettle 4.4

kettle作为ETL工具,其功能日趋完善,已得到广大数据挖掘爱好者的青睐.又因为他是java开源项目,为适应项目需求,有必要研究其源码,最好能够集成到Java项目中,作为项目运行流程的一个重要环节来使用. 那么,先让我们来瞅瞅kettle源码在eclipse 下的部署 和 版本的生成 首先,下载源码pdi-ce-src-4.4.0-stable-r17588.zip,解压到pdi-ce-src-4.4.0-stable-r17588文件夹 下一步,在eclipse菜单栏下点击 "File&qu

网狐棋牌源码教程 -安装运营帮助文档

v6603游戏数据库文档.doc6603平台图形文件要求6603经验等级与经验值的关系.docv6603游戏数据库字典.docv6603网狐游戏升级.docv6603网狐游戏服务启动配置方法.docv6603网站数据库字典.doc6603棋牌管理系统操作手册.doc6603机器人操作说明.doc库存值的解释.doc大厅搭建填写.doc棋牌_服务器填写.doc地址规则说明.doc网狐6603棋牌游戏产品介绍.doc 为棋牌爱好者免费提供视频教程下载.棋牌打包工具.棋牌架设工具.棋牌帮助文档.棋牌源

jQuery 源码分析和使用心得 - 文档遍历 ( traversing.js )

jQuery之所以这么好用, 首先一点就是$()方法和它强大的选择器. 其中选择器使用的是sizzle引擎, sizzle是jQuery的子项目, 提供高效的选择器查询. 有个好消息告诉大家, 就是sizzle可以独立使用, 如果你觉得jQuery太大但又非常喜欢它的选择器, 那不妨可以用sizzle. 感兴趣的话可以到官方网站了解. 本系列内部不准备解析sizzle的源码, 一是sizzle内容相对独立, 二是内容主要涉及算法, 与整体的代码设计关系不大, 三嘛, 我的实力有限, 遇到算法就退

[shiro学习笔记]第四节 使用源码生成Shiro的CHM格式的API文档

版本号为1.2.3的shiro API chm个事故文档生成. 获取shiro源码 编译生成API文档 转换成chm格式 API 获取shiro源码 shiro官网: http://shiro.apache.org/ 下载源码资源包,使用myeclipse/eclipse将代码增加project中.如: 须要使用到的jar包: 编译生成API文档 Created with Rapha?l 2.1.2项目Export选择java下的javadoc选择要导出的projectjava doc的配置设置

[shiro学习笔记]第四节 使用源代码生成Shiro的CHM格式的API文档

版本为1.2.3的shiro API chm个事故文档生成. 获取shiro源代码 编译生成API文档 转换成chm格式 API 获取shiro源代码 shiro官网: http://shiro.apache.org/ 下载源代码资源包,使用myeclipse/eclipse将代码加入工程中.如: 需要使用到的jar包: 编译生成API文档 Created with Rapha?l 2.1.2项目Export选择java下的javadoc选择要导出的工程java doc的配置设置结束 转换成ch

使用sphinx快速生成Python API 文档

一  简单介绍 不管是开源还是闭源,文档都是很重要的.当然理论上说,最好的文档就是代码本身,但是要让所有人都能读懂你的代码这太难了.所以我们要写文档.大部分情况,我们不希望维护一份代码再加上一份文档,这样做很容易造成文档和代码的不一致,程序员最讨厌更新文档了.所以最佳实践就是在程序员代码中加注释,然后通过构建脚本自通生成文档,包括html,latex,pdf等. 对应于Pyhon,有很多可供选择的工具: sphinx中文版介绍 Sphinx使用 reStructuredText作为标记语言(类似

Hadoop学习笔记(10) ——搭建源码学习环境

Hadoop学习笔记(10) ——搭建源码学习环境 上一章中,我们对整个hadoop的目录及源码目录有了一个初步的了解,接下来计划深入学习一下这头神象作品了.但是看代码用什么,难不成gedit?,单步调试呢? 看程序不能调那多痛苦啊,想看跟踪一下变量,想看一下执行路径都难. 所以这里,我们得把这个调试环境搭建起来.Hadoop的主要代码是用java编写的,所以这里就选用eclipse作为环境. Hadoop目录下,本身就可以为作eclipse的一个工程来操作,但这里我不想,我想自己来建一个工程,

Mac下使用eclipse查看Java源码

1.从http://jdk8.java.net中下载Java源码src.zip到本地, 2.在访达中shift+command进入"/资源库/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home"目录后,进入bin目录后新建Javadoc目录,将src.zip解压到该目录: 3.在eclipse中查看源码的快捷键为command+click(鼠标单击)即可查看源码 以String.equals方法为例,选中equals,然后co