Navigating a huge number of source files, especially opensource software written by others, has always been problematic to me. I typically resort to "find . -name *.java -exec grep ... {}\;" on Unix machines and "Search" button on Windows machines to locate specific files that use particular classes or methods. However, these approaches are quite crude and do not go very far.
So when I ran into Java2HTML, my first reaction was cautious. But as looked at some of the HTML generated by it here and here, my excitement grew. This is exactly what I needed. As you can see, Java2HTML converts Java source files rooted at a directory in a familiar javadoc style -- with top-left frame having the package names, bottom-left frame having the classnames and the right frame having the hyper-linked, colorized source files. This makes source files navigation really easy.
Not only this, it is also possible to link external packages and classes within a source file to their javadoc documentation over the Web. For example, all uses of JDK classes could be hyperlinked with the corresponding JavaDoc kept at Sun's site. I found this really cool.
The goodness doesn't stop here: Java2HTML has an Apache Ant task for the conversion. As I was looking for the ability to publish Java code on the Web for my own project and be able to generate it as part of my build process, this came really handy.
As I started using Java2HTML more and more, I started expecting more capabilities. Often, I download only binary distribution and getting the sources (when I can) only adds extra overhead. What if it could decompile a class file (or better, or class files of a jar file) and genrate the easily navigable HTML files! I have used DJ Java Decompiler on some occassions and have found it quite useful. Of course, the source output is not so nice as the one from Java2HTML.
I knew that DJ Java Decompiler uses Jad as the engine to convert class files into java files and adds the capability to work with jar files and provides a graphical user interface.
Wouldn't it be cool to combine Jad and Jav2HTML to generate HTML from source files, class files or jar files! Given that jar can unjar a jar file, Jad can decompile class files and Java2HTML can convert class files into HTML, it certainly seemed possible.
After a couple of hours of experimentation, I was ready with an Ant build.xml file that made it possible. I call it "Java Code to HTML Converter" or just jc2h. Feel free to download and use it. As you will see fronm the file header, I am releasing this file with GPL Version 2.
Unfortunately, you would need to download Java2HTML and Jad from their respective sites. I was thinking of packagin them all together but their licenses do not allow repackaging. Also, Jad is distributed in binary form and you must get the appropriate binary for your platform.
To use jc2h, you should have Apache Ant, Java2HTML and Jad. Have the bin directory of Apache Ant and the directory having the Jad executable in PATH. Also, include c2h.jar (part of Java2HTML download) in the CLASSPATH. Once this setup is done, issue the following command from the same directory that has jc2h build.xml file to generate HTML of source files in src
directory:
ant -Dsrcdir=src
For a jar file name code.jar, issue the command:
ant jar2html -Djarfile=code.jar
Play with jc2h and let me know if you find it useful.