Integrating Chromium as a web renderer in a java application with JCEF

Daniel Bischoff
Jun 1, 2016 · 3 min read

In this tutorial we will integrate chromium in a java application. With this setup we can use the browser as a rendering engine instead of swt, swing or other ui frameworks. For this we will use JCEF (java chromium embedded) to integrate chromium into our java application.

Image for post
Image for post

Chromium is the engine behind the google chrome browser. It is maintained by google and is constantly updated. To render the browser component into a java application we use JCEF. JCEF is a wrapper around the CEF (chromium embedded framework). CEF is written in c++ and a wrapper around the chromium browser engine. It simplifies using the chromium engine. CEF is used in many commercial products for rendering the ui like spotify, steam or origin. JCEF renders the browser into a Swing application.

Setting everything up

At first we will setup JCEF. We have two options here. First we can use a prebuilt version of JCEF. Problem here is that this is a very old version. Second we can build JCEF on our own. For the simplicity of this tutorial we will use the prebuilt version of JCEF.

When using the pre built version, the files for WebGL support are missing. When you build everything from scratch there will be additional files (d3dcompiler etc.) in the build’s output folder for WebGL support.

The javascript engine in the prebuilt version is slow compared to the engine in newer releases (). So if you want the newest and fastest javascript engine then build chromium yourself.

Go to and download the jcef built under Quick Links -> Downloads. Once you have done that create a new java project and copy all related files, so that your project looks like mine.

Image for post
Image for post

I put everything jcef related under the folder jcef. Then add jcef.jar to build path (right click on jcef.jar -> Build Path -> Add To Build Path) and most importantly add the jcef folder to the java library path (right click project -> Properties -> Java Build Path -> Libraries Tab -> expand jcef.jar -> edit native library location -> set it to this project’s jcef folder)

Image for post
Image for post

After that we are ready to program!

Implementing a simple demo

Let’s implement a simple demo app that opens google in our window. Create a new java class called App and add the following content:

Now right click an run as a java application. A window opening should appear.

Image for post
Image for post

Useful settings

You can use all chromium specific parameters with JCEF. You just have to add a string array with all the parameters you need, when instantiating the JCEF application.

final CefApp cefApp = CefApp.getInstance(new String[]{"-–disable-web-security"});

Be aware that adding these settings can be a securtiy threat when you load webpages you don’t own. Use these settings at your own risk!

If you want to load resources via XMLHTTPRequest locally via the file protocol, you have to add the parameter:

-–disable-web-security

If this is not enough for your application you can also add the parameter:

–-allow-file-access-from-files

Accessing the camera

If you want to allow access to your camera, you have to add the parameter:

–enable-media-stream

Disable pinch to zoom

When you are on a touch device and pinch, the browser will zoom all elements. This can be very annyoing as it can destroy your layout. To disable this behaviour add the the parameter:

–disable-pinch

Thank you for reading my article. I hope that i could give you a short introduction in how to embed chromium into a java application.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store