Download |

The Java2HTML Tool

### Contents

- Introduction
- Feature List
- Ant
- API
- Installing
- Requirements
- Options
- Example Usage:-
  - example1
  - example2
  - example3 TreeDemo.java.html#80
- Known Limitations and Future Extensions
- Support
- Change History
- License Agreement
- Credits
- Payment

### Introduction

Java2HTML is a simple-to-use tool which converts a bunch of Java Source Code into a col ouri zed and browsable HTML representation. Go to download (Version 1.3.1) to get the tool now and/or see some example outputs. You must read the License Agreement before downloading this software.

Java2HTML output has been tested with Microsoft Internet Explorer 4, 5, 6 and Netscape Navigator 4, running on NT and Solaris.

Java2HTML is used by thousands of organizations to publish their source code on the internet, including Sun Microsystems (Java Pet Store Demo 1.3.1) and Oracle (XML Example).

For discussions regarding Java2HTML please subscribe to to our mailing list:-

- Subscribe
- Unsubscribe

### Feature List

Main features include:-

- Converts Java Code into Colourized HTML.
- Specify TAB Spacing.
- Specify style and colour options of all Java keywords types via standard cascading style sheets.
- JavaDoc Look'n Feel.
- Links Class references into source code for Class definitions.
- Links external Class references into 'JavaDoc' output.
- Optional Line Number feature.
- API

### Ant

Java2HTML can be used from within Ant. View the Java2HTML Task documentation to see how to do this.

### API

Java2HTML can be used from within a Java program by using the Java2HTML API . This is only available in 1.3Beta onwards.

View the Java2HTML API example to see how to use it.

### Installing

Installing, assumes a certain level of technical knowledge.

- Unzip Java2HTML.zip into a temporary directory, using either WinZIP or the JDK jar tool (using "jar-xf Java2HTML.zip")
- Copy j2h.jar and one of the scripts to an appropriate area on your file system (e.g. C:\Tools\Java2HTML)
- Place the installation directory in your PATH.
- Edit the script to reflect the installation directory, or create an appropriate script if you are not using a DOS/Unix based operating system.
- Use of the scripts is optional, alternatively you can place the j2h.jar location in your class path, and type "java j2h" in its place or if you are using Java 2, you can type, "java -jar j2h.jar".
- Type, "j2h" to see if your installation has succeeded. You should see a usage description if it is has been successful.
- Alternatively you can now use Java2HTML from within Ant.

### Requirements

- Java2HTML is written in Java and therefore needs a Java 1.1 or above compatible JVM.

### Options

Type, " j2h" (if using the script) with no arguments to get a list of options.

Option | aka | Default | Description
-d <directory> | -destination | output | Specifies the HTML output directory.
-js <directory> | -javasource | current directory | Specifies the Java Source directory that will be converted to HTML. Repeat for each Java Source directory.
-jd <directory> [web_reference] | -javadoc | N/A | Used to specify JavaDoc directories that the generated HTML will link to. Specify the optional extra parameter [web_reference] to indicate the web address if the Java HTML is to be accessed from a web server.
-m | -margin | 0 | Margin size, with Line Numbers.
-t | -tab | 4 | The number of spaces that Tabs will be converted to.
-n | -name | Java Source | Name used in the frames.
-h | -help, /? or j2h with no arguments | N/A | Display Help Options.
-nh | -noheader | false | prevents the header from being displayed.
-nf | -nofooter | false | prevents the footer from being displayed.
-s | -simple | false | Simple output, just include the Java source and stylesheet.css files. Also package links will not be set within the source

In addition, Java2HTML will produce a "stylesheet.css", in the output directory which can be edited to change the colour or style scheme. (Warning: this will get overwritten if it already exists when you run j2h)

### Example Usage

To review the output of running Java2HTML, view the index.html produced in the output directory with your favorite web browser.

I highly recommend the use of the -jd option. You will nearly always want to link into the standard Java libraries, so you will typically supply the following parameter, "-jd C:\JDK1.2\DOCS\API". Use the -jd option for each set of Java Doc you have access to.

Assuming you are using the Dos or Unix scripts "j2h.bat" or "j2h", type the examples for the specified effects.

- j2h -js C:\JDK1.2\src
  This will produce HTML representation under output in the current directory, for the JDK1.2 public source code.
- j2h -js \home\billgates\dev\cooljavaproject -jd \usr\jdk1.2\docs\api \www\docs\jdk1.2\docs\api
  This will produce HTML representation under output for the cooljavaproject source code with links into the standard Java Doc output for the JDK1.2 libraries.
- j2h -n COOL_PROJECT -t 8
  This will produce HTML representation under output for any Java Source files in the current directory, with tabs set to 8 spaces and a title of COOL_PROJECT.
- j2h -m 4 COOL_PROJECT
  This will produce HTML representation under output for any Java Source files in the current directory, with line numbers and a title of COOL_PROJECT.
- j2h -js C :\dev\project1 -js C: \dev\project2 -jd C :\jdk1.2\docs\api -jd C: \JavaXML\docs\api
  This will produce HTML representation under output for any Java Source files under C:\dev\project1 or C:\dev\project2 with Java Doc links to the standard JDK1.2 API and the SUN Microsystems XML libraries.

#### Example Outputs

Examples are from the SUN Microsystems JDK 1.3 Demos. If you experience any strange problems whilst browsing these links, please email a description of the problem to support@java2html.com

- Example Output 1
  Shows Source code for JDK 1.3 Java 2D Demo, created with the following command:-

  j2h -js C:\jdk1.3.1\demo\jfc\Java2D -d examples\Java2D_demo -jd C:\jdk1.3.1\docs\api http://java.sun.com/products/jdk/1.3/docs/api -n JAVA2D_DEMO

- Example Output 2 (with line numbers)
  Shows Source code for JDK 1.3 SwingSet2 Demo, created with the following command:-

  j2h -js C:\jdk1.3.1\demo\jfc\SwingSet2 -d examples\SwingSet_demo -jd C:\jdk1.3.1\docs\api http://java.sun.com/products/jdk/1.3/docs/api -n SwingSet_DEMO -m 4

- Example Output 3 - TreeDemo.java.html#80

Note: These examples use the web_reference feature of the -jd option, to point the web documentation at the Sun Java website. It would be more typical in general use to point the web_reference at your own local copy of the documentation.

### Known Limitations and Future Extensions

Please send requests for enhancements to support@java2html.com If I use your ideas I will give you a credit in this document.

- Support for Apples Macs and a java properties file to specify options.
- Method and Object Instance hyper links.
- Make use of a proper installer package.
- Hyper links of references within comments and strings
- Style sheet option, to prevent the overwriting of a customized stylesheet.
- Better handling of non-conformant java code.
- Extend Java2HTML to deal with other languages such as JSP, SQLJ, XML, SQL scripts, Perl and C/C++ and/or extend the architecture to allow third parties to implement additional language sources.
- Possibly publish the source code with an appropriate license.
- HTML driven Search Facility.
- Tony O'Hagan suggested providing a -link option so that JavaDoc can be linked directly from a URL.

### Support

Please report bugs to support@java2html.com, before emailing make sure that the bug is not listed in Known Limitations and Possible Extensions.

### Change History

Version | Date | Change
1.0 | 19th Aug 1999 | Release
1.0.1 | 20th Aug 1999 | front.html now appears with white background on all mainstream browsers. (See Version Change 1.0.3)
|  | Fixed JavaDoc URL Reference, now uses "/", instead of "\" which does not work with all mainstream browsers.
1.0.2 | 23rd Aug 1999 | Fixed Java Source URL Reference now uses "/", instead of "\" which does not work with all mainstream browsers.
|  | Added extra information in the usage description.
1.0.3 | 5th Sept 1999 | front.html now appears with white background on all mainstream browsers. (Accidentally not released in Version 1.0.1)
|  | when using the -jd option with a single parameter it will now automatically convert the parameter into proper URL references in the JavaDoc links. (This can be done anyway using the second parameter). Requested by Anand Santhanam & David Karr, .
|  | Java2HTML now deals with accented characters properly. Thanks to Gerald Pfarrand & Martin Desruisseaux for spotting that one.
|  | Tidied up HTML generation in many places.
|  | Added manifest file to j2h.jar. This allows Java 2 users to type, "java -jar j2h.jar". Thanks to Martin Desruisseaux for that.
    interface A {
        class B {};  // <-- ';' is problematic
    }
The above code would generate a parse error in Java2HTML. Not anymore. Thanks to Kang Pilsung for spotting that.
1.0.4 | 27th Oct 1999 | Returns exit code, for better integration with Scripting Languages. Requested by Kaze
|  | Improved Line Number rendering. (Looks a lot better now)
|  | Added more information to front.html.
1.0.5 | 4th Nov 1999 | Fixed typo on front.html.
|  | Error message inserted into HTML output for Non Legal Java files.
    class Foo {
      SomeObject thing = something;; // <-- Extra semi-colon
    }
The extra semi-colon would generate a parse error. Not anymore. Thanks to Mike for spotting that. You're right Mike, even though it isn't Kosher Java, most of the compilers accept it.
1.0.6 | 17th Nov 1999 | Output messages have been improved.
|  | Catches Lexical Errors properly. Thanks to Jason King of Sun MicroSystems for pointing that out.
|  | Added Meta "GENERATOR" Tag to all generated pages.
1.0.7 | 31st Oct 2000 | Added Line Number Tags. So you can no use URL references such as, TreeDemo.java.html#80
|  | Fixed typos in the j2h usage message. Thanks to Robert Biuk-Aghai of University of Technology, Sydney, for so kindly pointing that out. He also noted a few typos on this page which have also been fixed.
|  | Deprecated the -dir option. Java2HTML now uses a superior (if what slower) two-parse mechanism.
|  | Please note that ownership of Java2HTML has now been transferred to RiteLink Computing Limited.
|  | Added j2h wrapper class.
|  | Added -nh -nf options to remove Header and Footer.
|  | Import lists in source now link to JavaDoc.
|  | Package declaration in source now links to package frame.
|  | Operating System "new line" is used throughout generated HTML, instead of hard coded DOS/NT new line.
|  | Changed 'Package' to 'Packages' text in top left frame.
|  | Fixed single line comment on last line parse failure bug, also spotted by Brad Wells.
1.0.8 | 11th Nov 2000 | Fixed "Project" hyper text reference (top Right hand Corner) to refer to front.html instead of FRONT.HTML.
1.0.9 | 2nd Feb 2002 | Fixed some HTML output bugs, most importantly line number anchors were not being terminated with </A>. Spotted by a Peter Luschny, Markus.Schmidt and Andreas Schenk
|  | Changed the instructions on the front page so that 'this' in 'Text displayed like this represents', is in the same style as the actual links within Java Source. Thanks for Christophe Laprun for pointing that out.
|  | Operating System "new line" is now used in the generated stylesheet. Thanks again to Robert Biuk-Aghai for that.
1.1 | 15th Oct 2002 | Footer/Header not correct for Netscape Browser
|  | Now recognizes .super() method Calls. Spotted by Jim Fisher.
|  | Added Support for Java Version 1.4.
|  | Fixed problem with /**/ when it appeared more than once within a file.
|  | Fixed problem with use of \u9999. (This problem was originally fixed in an earlier version but got reintroduced)
1.2 | 25th Oct 2002 | Expanded the lexical range of characters allowed for a java identifier, requested by Dirk Zoettl
|  | Added ".java" to the header and changed the background colour.
1.3beta | 2nd Feb 2003 | default.index.html replaces .index.html, Raised by Tanguy PERENNOU
|  | Moved Java2HTML to an ANT based build script
|  | Numerous changes to the internals of Jav2HTML.
|  | Ownership of Java2HTML Transferred to Polygon Enterprises
|  | Better supports Integration with Ant
|  | Published Java2HTML API.
1.3Beta2 | 22nd Feb 2003 | Fixed 'null' bug when no JavaDoc option was set
|  | Added -simple option
1.3Beta3 | 23rd Feb 2002 | (Internal changes only)
1.3Beta4 | 23rd April 2003 | Added Ant Support, recommended by numerous users.
|  | Fixed -jd command line option problem. Spotted by Cal Holman
|  | Changed the Java2HTML API to support Ant.
|  | Removed references to the deprecated -dir option.
1.3 | 28th April 2003 | No Changes
1.3.1 | 15 May 2003 | (Internal changes only)

### License Agreement

You should carefully read the following terms and conditions before using this software package. Your use of this software package indicates your acceptance of this license agreement. This is a legal agreement (this "Agreement") between you (either an individual or an entity) and the proprietor of this software. This Agreement is part of the software package.

1. GRANT OF LICENSE. The proprietor hereby grants you a personal, non-exclusive, non-transferable license to use one copy of this Software. This grant of license gives the right to use the software on your computer. You may not decompile, disassemble, or reverse engineer this software, and you may not create derivative works of the this software. You may modify, translate or adapt the generated HTML code. You are not granted any right, title, or interest in the the software except the right to use it in accordance with this Agreement.

2. REDISTRIBUTION Redistribution of the software ZIP file is allowed by shareware and freeware sites or CDROM media and similar without the permission of the proprietor. Redistribution for commercial purposes or reselling is not allowed.

3. WARRANTY. This software and the accompanying files are provided "AS IS," without a warranty of any kind.

4. COPYRIGHT. Copyright is owned by Polygon Enterprises and is protected by United Kingdom copyright law and international treaty provisions.

5. TERMINATION The license will terminate immediately without notice from the proprietor if you fail to comply with any provision of this license. Upon termination, you must destroy all copies of the software and its components on any and all forms of media.

6. LIMITATION OF LIABILITY IN NO EVENT WILL THE PROPRIETOR OR ITS SUPPLIERS BE LIABLE FOR ANY LOST REVENUE, PROFIT, OR FOR DIRECT, SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES HOW EVER CAUSED AND REGARDLESS OF THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IF THE PROPRIETOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

7. GOVERNING LAW This agreement is made under, shall be governed by and construed in accordance with, the laws of the United Kingdom.

### Credits

- Sun MicroSystems, thanks for making Java.
- Peter Van der Linden, Maintainer of the Java FAQ, and author of "Just Java 1.2" as well as many other good books.
- The people who put together JavaCC, especially Siram Sankar for his help.
- Guys on the JavaCC newsgroup, including David Williams for his Java 1.2 extensions.
- Thanks to the people at JARS for giving this tool (version 1.0.3) a, "rated JARS Top 25%", although it actually got 895 out of a 1000, losing marks on presentation :-(
- Jason Shattu, the original creator of Java2HTML.
- Polygon Enterprises, the owners of this product.
- Other good products out there:-
  - Bruce Blackshaw's Java FTP Client
  - David Shattu's Easy Password Manager

### Payment

Java2HTML is distributed as free software but should a user or company make significant use of it, they are encouraged to make a $50 contribution which gives them registration status and helps towards future development costs. Please click on the following link.

last updated: May 31 2003 |  |