How to convert Java source code to HTML page

Java2HTML is a tool to converts Java source code into a colorized and browsable HTML page, and the steps are quite straight forward.

Steps to convert it

1) Download Java2HTML – http://www.java2html.com/download.html

2) Unzip it , e.g “D:\Java2HTML”

3) Edit the “j2h.bat” file and modify the CLASSPATH variable. Make sure it point to the correct j2h.jar library.


@echo off
REM Change this Script, to suit your needs

REM The next few line combines the command line args into one
set _j2h_parameter=
:GetParameter
if "%1" == "" goto end
set _j2h_parameter=%_j2h_parameter% "%1"
shift
goto GetParameter
:end

REM runs Java2HTML
set MBACKUP=%CLASSPATH%
set CLASSPATH=D:\Java2HTML\j2h.jar;%CLASSPATH%
java j2h %_j2h_parameter%
set CLASSPATH=%MBACKUP%

4) Set the “j2h” into Windows environment variable. (If you need access the command globally)

5) Issue the following command


C:\>j2h -js D:\Java2HTML\source -d D:\Java2HTML\output

D:\Java2HTML\source is the Java source code to convert
D:\Java2HTML\output is the generated HTML output folder

Result

– Here is an example to convert all the TestNG source codes into HTML pages.


C:\>j2h -js D:\Java2HTML\source -d D:\Java2HTML\output
Java2HTML Version 1.5
Copyright (c) 1999-2007, Enterprise Solution Consultants Limited, All Rights Reserved.
New Versions available from http://www.java2html.com
(type j2h with no arguments to get help)
Created D:\Java2HTML\output\stylesheet.css
Created D:\Java2HTML\output\front.html
Created: D:\Java2HTML\output\org\testng\internal\Invoker.java.html
Created: D:\Java2HTML\output\org\testng\ClassMethodMap.java.html
Created: D:\Java2HTML\output\org\testng\v6\TestPlan.java.html
Created: D:\Java2HTML\output\org\testng\annotations\Test.java.html
Created: D:\Java2HTML\output\org\testng\internal\annotations\JDK14TagFactory.java.html
Created: D:\Java2HTML\output\org\testng\annotations\AfterMethod.java.html
Created: D:\Java2HTML\output\org\testng\internal\TestMethodWorker.java.html
Created: D:\Java2HTML\output\org\testng\JUnitConverter.java.html
Created: D:\Java2HTML\output\org\testng\internal\BaseClassFinder.java.html
Created: D:\Java2HTML\output\org\testng\internal\AnnotationTestConverter.java.html
Created: D:\Java2HTML\output\org\testng\junit\JUnitDirectoryConverter.java.html
Created: D:\Java2HTML\output\org\testng\JUnitConverterTask.java.html
Created: D:\Java2HTML\output\org\testng\remote\strprotocol\GenericMessage.java.html
Created: D:\Java2HTML\output\org\testng\xml\ClassSuite.java.html
Created: D:\Java2HTML\output\org\testng\internal\thread\ThreadTimeoutException.java.html
Created: D:\Java2HTML\output\org\testng\internal\BaseTestMethod.java.html
Created: D:\Java2HTML\output\org\testng\annotations\TestInstance.java.html

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
7 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
7 Comment authors
Biplab HossainTheTech SolShrikantrajsreehareesh48 Recent comment authors
newest oldest most voted
raj
Guest
raj

How can we write a java code into html and execute with my own server program???

Biplab Hossain
Guest
Biplab Hossain

Thanks for the sharing informative post. I like this blog and also visit again and again. I applied this my blog let’s Visit my blog site TV lives24.com.

TheTech Sol
Guest
TheTech Sol

Thanks its really helpful

Another easy way how to use java2html step by step complete guide

http://www.thetechsol.com/2014/01/how-to-get-html-code-of-eclipse-java.html

Shrikant
Guest
Shrikant

hilite.me is another good site that has various themes for code formatting. You can convert codes from various languages(and the list of languages is really awesome)

sreehareesh48
Guest
sreehareesh48

you can convert using editplus. watch it.

http://www.youtube.com/watch?v=IofQ6jRnm5g

madman
Guest
madman

hi..
is this possible to convert pdf file to html file using java?
thank you.

vbnandu86
Guest
vbnandu86

Or you can use this online tool for conversion

http://java2html.blogspot.in/2012/06/convert-java-source-to-html.html

No downloads!