JHighlight is an embeddable pure Java syntax highlighting library.
Java
25
63 commits
updated Sep 10, 2026
A pure Java syntax highlighting library that generates XHTML output from source code. This is a maintained fork of the original jhighlight project with critical bug fixes, particularly for multi-byte character handling.
<dependency>
<groupId>org.codelibs</groupId>
<artifactId>jhighlight</artifactId>
<version>1.1.0</version>
</dependency>
implementation 'org.codelibs:jhighlight:1.1.0'
import org.codelibs.jhighlight.renderer.XhtmlRendererFactory;
import org.codelibs.jhighlight.renderer.Renderer;
import java.io.*;
// Get a renderer for Java code
Renderer renderer = XhtmlRendererFactory.getRenderer("java");
// Highlight code from an input stream
InputStream input = new FileInputStream("Example.java");
OutputStream output = new FileOutputStream("Example.java.html");
renderer.highlight("Example.java", input, output, "UTF-8", false);
# Highlight a single file
java -jar jhighlight.jar MyClass.java
# Highlight all files in a directory
java -jar jhighlight.jar src/
# Specify output directory and encoding
java -jar jhighlight.jar -d output -e UTF-8 src/
# Generate fragments instead of complete HTML documents
java -jar jhighlight.jar --fragment MyClass.java
| Option | Description |
|---|---|
--verbose | Output progress messages |
--fragment | Generate HTML fragments instead of complete documents |
-d <dir> | Specify destination directory for output files |
-e <encoding> | Specify file encoding (default: UTF-8) |
| Language | File Extensions | Renderer Type |
|---|---|---|
| Java | .java | java |
| Groovy | .groovy | groovy |
| BeanShell | .bsh, .beanshell | beanshell / bsh |
| JavaScript | .js | (via factory) |
| C++ | .cpp, .cxx, .c++ | cpp / cxx / c++ |
| XML | .xml | xml |
| HTML | .html, .htm | html |
| XHTML | .xhtml | xhtml |
| LZX | .lzx | lzx |
import org.codelibs.jhighlight.renderer.XhtmlRendererFactory;
Set<String> supportedTypes = XhtmlRendererFactory.getSupportedTypes();
System.out.println("Supported types: " + supportedTypes);
The original jhighlight library (from jhighlight.dev.java.net) had critical issues with multi-byte character handling, causing garbled output for source files containing UTF-8 characters, Japanese, Chinese, Korean, and other non-ASCII text. This fork fixes those issues and is actively maintained.
If you're using Apache Tika (which depends on the original jhighlight), you'll need to exclude the old dependency and include this version:
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.6</version>
<exclusions>
<exclusion>
<groupId>com.uwyn</groupId>
<artifactId>jhighlight</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codelibs</groupId>
<artifactId>jhighlight</artifactId>
<version>1.1.0</version>
</dependency>
This fork maintains the original package structure with additions:
com.uwyn.jhighlight.*org.codelibs.jhighlight.*Most classes are now available in the org.codelibs.jhighlight package for better namespace management.
# Clone the repository
git clone https://github.com/codelibs/jhighlight.git
cd jhighlight
# Build with Maven
mvn clean install
# Run tests
mvn test
# Generate code coverage report
mvn jacoco:report
The compiled JAR will be available in the target/ directory.
import org.codelibs.jhighlight.servlet.HighlightFilter;
// Configure in web.xml
<filter>
<filter-name>HighlightFilter</filter-name>
<filter-class>org.codelibs.jhighlight.servlet.HighlightFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HighlightFilter</filter-name>
<url-pattern>*.java</url-pattern>
</filter-mapping>
The generated XHTML includes CSS classes that you can style:
<span class="java_keyword">public</span>
<span class="java_type">class</span>
<span class="java_plain">Example</span>
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
mvn testThis project is dual-licensed under:
You may choose either license to govern your use of this software.
748 followers · starred Dec 2018
Java
96.5%
Lex
3.5%
JHighlight is an embeddable pure Java syntax highlighting library.
Java
25
63 commits
updated Sep 10, 2026
A pure Java syntax highlighting library that generates XHTML output from source code. This is a maintained fork of the original jhighlight project with critical bug fixes, particularly for multi-byte character handling.
<dependency>
<groupId>org.codelibs</groupId>
<artifactId>jhighlight</artifactId>
<version>1.1.0</version>
</dependency>
implementation 'org.codelibs:jhighlight:1.1.0'
import org.codelibs.jhighlight.renderer.XhtmlRendererFactory;
import org.codelibs.jhighlight.renderer.Renderer;
import java.io.*;
// Get a renderer for Java code
Renderer renderer = XhtmlRendererFactory.getRenderer("java");
// Highlight code from an input stream
InputStream input = new FileInputStream("Example.java");
OutputStream output = new FileOutputStream("Example.java.html");
renderer.highlight("Example.java", input, output, "UTF-8", false);
# Highlight a single file
java -jar jhighlight.jar MyClass.java
# Highlight all files in a directory
java -jar jhighlight.jar src/
# Specify output directory and encoding
java -jar jhighlight.jar -d output -e UTF-8 src/
# Generate fragments instead of complete HTML documents
java -jar jhighlight.jar --fragment MyClass.java
| Option | Description |
|---|---|
--verbose | Output progress messages |
--fragment | Generate HTML fragments instead of complete documents |
-d <dir> | Specify destination directory for output files |
-e <encoding> | Specify file encoding (default: UTF-8) |
| Language | File Extensions | Renderer Type |
|---|---|---|
| Java | .java | java |
| Groovy | .groovy | groovy |
| BeanShell | .bsh, .beanshell | beanshell / bsh |
| JavaScript | .js | (via factory) |
| C++ | .cpp, .cxx, .c++ | cpp / cxx / c++ |
| XML | .xml | xml |
| HTML | .html, .htm | html |
| XHTML | .xhtml | xhtml |
| LZX | .lzx | lzx |
import org.codelibs.jhighlight.renderer.XhtmlRendererFactory;
Set<String> supportedTypes = XhtmlRendererFactory.getSupportedTypes();
System.out.println("Supported types: " + supportedTypes);
The original jhighlight library (from jhighlight.dev.java.net) had critical issues with multi-byte character handling, causing garbled output for source files containing UTF-8 characters, Japanese, Chinese, Korean, and other non-ASCII text. This fork fixes those issues and is actively maintained.
If you're using Apache Tika (which depends on the original jhighlight), you'll need to exclude the old dependency and include this version:
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.6</version>
<exclusions>
<exclusion>
<groupId>com.uwyn</groupId>
<artifactId>jhighlight</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codelibs</groupId>
<artifactId>jhighlight</artifactId>
<version>1.1.0</version>
</dependency>
This fork maintains the original package structure with additions:
com.uwyn.jhighlight.*org.codelibs.jhighlight.*Most classes are now available in the org.codelibs.jhighlight package for better namespace management.
# Clone the repository
git clone https://github.com/codelibs/jhighlight.git
cd jhighlight
# Build with Maven
mvn clean install
# Run tests
mvn test
# Generate code coverage report
mvn jacoco:report
The compiled JAR will be available in the target/ directory.
import org.codelibs.jhighlight.servlet.HighlightFilter;
// Configure in web.xml
<filter>
<filter-name>HighlightFilter</filter-name>
<filter-class>org.codelibs.jhighlight.servlet.HighlightFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HighlightFilter</filter-name>
<url-pattern>*.java</url-pattern>
</filter-mapping>
The generated XHTML includes CSS classes that you can style:
<span class="java_keyword">public</span>
<span class="java_type">class</span>
<span class="java_plain">Example</span>
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
mvn testThis project is dual-licensed under:
You may choose either license to govern your use of this software.
748 followers · starred Dec 2018
Java
96.5%
Lex
3.5%