简体   繁体   中英

How to generate JavaDoc documentation for classes without source?

I would like to generate some basic html interface documentation (without comments of course) of the class files within a jar to which I do not have source. How can I go about doing this?

The old tool of classdoc [Class Doc][1]http://classdoc.sourceforge.net/ which was available for java 1.3 used to provide this service. It seems to me that this can be done via the use of reflection.

Any ideas or examples using javadoc or another utility on how to perform this seemingly simple task on 1.6 or 1.7 classes?

There are maybe automated solutions but I do not know any. My best bet would be to write manually some code which will generate dummy java files with javadoc inside. You'll have to browse the jar file using something like this:

ArrayList<Class> classes = new ArrayList<Class>();    
    JarFile jfile = new JarFile("your jar file name");
    String pkgpath = pckgname.replace(".", "/");     
    for (Enumeration<JarEntry> entries = jfile.entries(); entries.hasMoreElements();) {
        JarEntry element = entries.nextElement();     
        if(element.getName().startsWith(pkgpath)
            && element.getName().endsWith(".class")){     
            String fileName = element.getName().substring(pckgname.length() + 1);     
            classes.add(Class.forName(pckgname + "." + fileName .split("\\.")[0]));     
        }     
    }

Then for each class you'll have to browse their methods to finally write down the dummy classes which look like the original ones in the jar file. While the code write the dummy methods to file, make it also write javadoc comments based on what the parameters and the return type are.

Once this is done use javadoc to generate the documentation from your dummy classes.

This might be a bit long to do but that's my guess for this one...

您可以使用jar tvf yourjar.jar列出类,并使用javap来反汇编类,它会产生一个非常清晰的文档。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM