Java 9 REPL – Getting started guide

 In Java

At jClarity we’re heavily involved in the Java community as speakers, authors and Java User Group (JUG) leaders. One of the programmes we help run is Adopt OpenJDK, a community lead group of technologists who work with/on OpenJDK (Java itself). The main focus for Adopt OpenJDK is to run workshops and hackdays on early Java features before they make their way into Java proper. On Sunday the 12th of April we ran a hackday on the upcoming Java 9 REPL (aka Kulla), here’s how you can try it yourself!

Project Kulla

Kulla (“The God of Builders”) is the code name for the Java REPL coming into Java 9. The official project page has links to the mailing list etc.

1. Install JDK 9

Install your JDK 9 for your operating system. The Latest JDK 9 beta build for your platform – build 59 at time of writing.

Mac OS X

Please note that for Mac OS X in particular this will set your JAVA_HOME and PATH to use this JDK 9, this blog post shows you how to work around that.

Verify install

Run the following on the command line to ensure you have the right JDK installed, you’ll see something like this.

% java -version 
java version "1.9.0-ea"
Java(TM) SE Runtime Environment (build 1.9.0-ea-b59)
Java HotSpot(TM) 64-Bit Server VM (build 1.9.0-ea-b59, mixed mode)
         
% javac -fullversion
javac full version "1.9.0-ea-b59"

2. Download and install jline2

git clone git://github.com/jline/jline2.git
cd jline2
mvn install

Build kulla

hg clone http://hg.openjdk.java.net/kulla/dev kulla
chmod u+x get_source.sh
./get_source.sh
cd kulla/langtools/repl

Edit the compile script

Please note that:

  1. #!/bin/sh on Mac OS X is #!/usr/bin/sh on Linux
  2. JLINE2LIB should point to the jline2 SNAPSHOT JAR you built with Maven
  3. JAVAC_BIN_HOME should point to the javac of the JDK 9 you’ve recently installed

Edit the Compile script, e.g. vi ./scripts/compile.sh so it looks similar to:

#!/bin/sh
JLINE2LIB=/Users/karianna/Documents/workspace/AdoptOpenJDK_projects/jline2/target/jline-2.13-SNAPSHOT.jar
JAVAC_BIN_HOME=/Library/Java/JavaVirtualMachines/jdk1.9.0.jdk/Contents/Home/bin

mkdir -p build
$JAVAC_BIN_HOME/javac -Xlint:unchecked -Xdiags:verbose -cp ${JLINE2LIB} -d build src/*/*.java

Run the compile script, e.g. ./scripts/compile.sh

Run Kulla

Edit the Run script, e.g. vi ./scripts/run.sh so it looks similar to:

Please note that:

  1. #!/bin/sh on Mac OS X is #!/usr/bin/sh on Linux
  2. JLINE2LIB should point to the jline2 SNAPSHOT JAR you built with Maven
  3. JAVA_BIN_HOME should point to the java of the JDK 9 you’ve recently installed
#!/bin/sh
JLINE2LIB=/Users/karianna/Documents/workspace/AdoptOpenJDK_projects/jline2/target/jline-2.13-SNAPSHOT.jar
JAVA_BIN_HOME=/Library/Java/JavaVirtualMachines/jdk1.9.0.jdk/Contents/Home/bin/

$JAVA_BIN_HOME/java -ea -esa -cp build:${JLINE2LIB} tool.Repl "$@"

Run the run script, e.g. ./scripts/run.sh

You’ll then see a CL prompt like:

% java -jar kulla.jar 
|  Welcome to the Java REPL -- Version 0.411
|  Type /help for help

Hello World

-> System.out.println("Hello World!");
Hello World!

Tutorial

Once you’ve completed the Hello World example, you can try out the basic Tutorial.

Feedback

The official project page has links to the mailing list where feedback will be appreciated!

Cheers,
Martijn (CEO) and the jClarity Team!

Say goodbye to Java performance problems!

No more memory leaks and application pauses!

Recent Posts
Showing 2 comments
  • anjan.bacchu

    nice article. thank you.

    “git clone https://github.com/jline/jline2.git” works in my environment . The one you specified with the git protocol didn’t work in my corporate environment. Can you mention this as well so others might benefit ?

pingbacks / trackbacks
  • […] Getting started with Java 9 REPL – One of the newest features expected to arrive in Java 9 is a Read-Eval-Print-Loop, a helpful tool for interactive programming. There is already an independent REPL for Java, but Project Kulla offers an official implementation, coming to JDKs near you. How does this work you may ask? What are the benefits of using a REPL? Download the latest build today and see for yourself! […]

Leave a Comment

0