In this post I’ll explain how you can run Java 9 workspaces in Eclipse Che.

Background

Eclipse Che uses the Eclipse JDT (Java Development Tools) to do all the Java language services in the IDE (code completion, refactoring, etc…). Now that Eclipse Che is moving towards using only LSP (Language Server Protocol) implementations it’s easier to maintain these language services, and there is a clear separation between the IDE part and the language part.

With Che 5.x, we had a JDT instance running on the server side. It was a custom JDT patched to get rid of all the UI that we couldn’t use in the browser-based Che IDE.

With Che 6 (usable now but due to GA in January 2018) we now have a JDT instance packaged as part of jdt.ls language server protocol implementation.

eclipse/eclipse.jdt.ls
_eclipse.jdt.ls - Java language server_github.com

You may know already that the eclipse.jdt.ls was developed by Red Hat and is also used for the Java extension on VS Code.

Language Support for Java(TM) by Red Hat - Visual Studio Marketplace
_Extension for Visual Studio Code - Language Support for Java(TM) for Visual Studio Code provided by Red Hat_marketplace.visualstudio.com

It means that all improvements, bugfixes, etc. that are done inside jdt.ls are then shared for many products — the true meaning of Christmas (and community)!

However, in Eclipse Che there are a few things for Java that aren’t part of the Language Server Protocol — these Che-specific items have been built into the Che jdt.ls project: https://github.com/eclipse/che-ls-jdt

Now that we had a language server compliant with Java 9 we needed to enable it in Che. For now this work is only available through a feature branch named 5730_Java_ls_pocin the Che repo. So I needed to build this branch and then create Docker images for it so that others (like you) that want to try it don’t need to checkout or build a branch!

You can skip the next section if you only want to run your workspace and aren’t interested in rebuilding Che (it’s not necessary to).

Building Che Server Docker Images

After successfully building the branch I can also make the Che server Java 9 compliant.

We could use Alpine Linux with Java 9 to have a small image but there is no OpenJDK9/Alpine yet. And it’s probably not going to happen soon based on the following issue.

Create 9-alpine · Issue #100 · docker-library/openjdk
_Can we get a JDK 9 on alpine 3.5?_github.com

As part of experimenting with stuff, let’s use Eclipse OpenJ9 — a JVM under the Eclipse Foundation (obviously we’re fans of the Foundation).

OpenJ9
_Eclipse OpenJ9 is a high performance, scalable, Java virtual machine (JVM) implementation that represents hundreds of…_www.eclipse.org

AdoptOpenJDK provides a Docker image we can use:adoptopenjdk/openjdk9-openj9

https://hub.docker.com/r/adoptopenjdk/openjdk8-openj9/

I’ve used the following Dockerfile to build the Che image.

eclipse/che
_che - Eclipse Che: Next-generation Eclipse IDE. Open source workspace server and cloud IDE._github.com

In the end, I’ve successfully build the server image from the jdt.ls branch named florentbenoit/che-server:jdtls and it’s based on the OpenJ9 adoptopenjdk/openjdk9-openj9 Docker image. I’ve also published the image so everyone can use it.

Using Java 9 in my Workspace

Let’s start Eclipse Che. I’m using /tmp/jdtls as folder to store the data.

$ docker run -it –rm -v /var/run/docker.sock:/var/run/docker.sock -v /tmp/jdtls:/data florentbenoit/che:jdtls start –fast

The output should look like:

INFO: Proxy: HTTP_PROXY=, HTTPS_PROXY=, NO_PROXY=*.local, 169.254/16
INFO: (che cli): jdtls - using docker 17.11.0-ce / docker4mac
INFO: (che config): Generating che configuration…
INFO: (che config): Customizing docker-compose for running in a container
INFO: (che start): Starting containers…
INFO: (che start): Services booting…
INFO: (che start): Server logs at “docker logs -f che”
INFO: (che start): Booted and reachable
INFO: (che start): Ver: jdtls
INFO: (che start): Use: http://localhost:8080
INFO: (che start): API: http://localhost:8080/swagger

We can check that the server is running Java 9:

$ docker logs 2>&1 che | grep “JVM “
- JVM Version: 9-internal+0-adhoc.jenkins.openjdk
- JVM Vendor: Eclipse OpenJ9

Great, let’s connect to http://localhost:8080 and create a new workspace.

Since this is all new work, we’ll need to create a custom Che workspace with Java 9 installed — luckily that’s not hard! I’ve published a florentbenoit/ubuntu_jdk9 Docker image containing OpenJDK9 on top of the ubuntu:17.10 Docker image. It also includes maven.

Check that the image is set to florentbenoit/ubuntu_jdk9.

Also, be sure that the Java LSP agent is enabled, if it’s not you won’t get any of the language server features like code completion, etc…

You can show the config of the workspace and it should include the agent org.eclipse.che.ls.java (line 28 below)

When the correct Docker image is set and the Java LS agent is defined, we can start the workspace.

Let’s import a maven project from https://github.com/benoitf/jdtls-maven-example

benoitf/jdtls-maven-example
_jdtls-maven-example - Java9 + maven + jdt.ls example_github.com

After the project is imported, you can then try to type Java 9 code. You should have code completion and javadoc for Java 9 features.

Voilà! You can use Java 9 inside your projects now!

In the next post we’ll look at how to compile and run the Che project (as a contributor) with Java 9.

As always please let us know your thoughts by connecting with us on twitter @eclipse_che or by filing issues in the Che GitHub repo at https://github.com/eclipse/che