3

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?

Kevin Bedell
  • 13,254
  • 10
  • 78
  • 114
  • This might help you: http://stackoverflow.com/questions/29689/javadoc-template-generator –  May 08 '12 at 14:31

2 Answers2

1

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...

Max
  • 3,453
  • 3
  • 32
  • 50
1

You can use jar tvf yourjar.jar for listing the classes, and javap for disassembling the classes, it yields a very legible documentation.

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
louis35
  • 71
  • 4