Java 9 on Java EE 8 Using Eclipse and Open Liberty

This post was originally written by Martin Farrell.

I wrote a post a few weeks ago titled Which IDEs and Servers support Java EE 8 and Java 9 which looked at the current state of play between Java 9 and Java EE 8. As you would expect things have moved quickly and we now have some alpha and development builds of Open Liberty supporting Java 9 and Java EE 8.

Adam Bien posted a video Java EE 8 on Java 9 on how to deploy a Java 9 application on Open Liberty using Netbeans. Its a great video and worth a look.

I decided to use the same approach as Adam to deploy a JSF Application on Eclipse Oxygen.

This post deals with installation and the first part of the project installing the core application, the next post will expand on this by building a JSF 2.3 application.

Installation

Java 9

Ensure you are running Java 9 on both classpath and JAVA_HOME, and also ensure you have maven installed.

Open Liberty

Open Liberty came from IBM open sourcing WebSphere Liberty, and is a fully compliant Java EE 7 server. They also have an early release Java EE 8 server, which is getting improved all the time in their development builds. We will use a development build for this project, which can be downloaded from here.

Eclipse

Eclipse Oxygen also has a Java 9 release available here – I am using the Java EE version of the Eclipse.

Work through the installation instructions. This is just unzipping Open Liberty Server to your preferred location, and similarly for Eclipse Oxygen.

Start Eclipse Oxygen:

Installing Open Liberty on Eclipse Oxygen

Finally we need to install “IBM Liberty Development Tools for Oxygen” – Help > Eclipse Marketplace.

Then connect up our Open Liberty server on the Servers tab:

Finally point at your Open Liberty deployment location, and ensure you are using Java 9:

You can click finish here.

Finally we need to install the Java EE 8 Feature:

>> Double Click “WebSphere Application Server Liberty”.

>> Click “Open server configuration” then “Feature”.

>> Then “Add…” and select “javaee-8.0”.

I would also remove JSF 2.3 as that’s included in javaee-8.0.

You could start the server now if you want.

First Project

The best archetype I have found for Java EE 8 is also from Adam Bien.

To run it simply type:

mvn archetype:generate -DinteractiveMode=false -DarchetypeGroupId=com.airhacks -DarchetypeArtifactId=javaee8-essentials-archetype -DarchetypeVersion=0.0.2 -DgroupId=com.javabullets.javaee8 -DartifactId=javaee8

Then let’s compile straight away and make sure there are no errors:

E:\code\javaee8>mvn clean package

Note the archetype is compiled against Java 8, we will move it to Java 9 in the next section.

The source code is available at https://github.com/farrelmr/javaee8.

Open in Eclipse

In “Enterprise Explorer” select:

Import > Import… > Maven > Existing Maven Projects.

Navigate to your Java EE 8 directory, click Finish and let Eclipse load your project into Eclipse.

Open the pom.xml file and change source and target from 1.8 to 1.9:

<properties>
    <maven.compiler.source>1.9</maven.compiler.source>
    <maven.compiler.target>1.9</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>

Then run maven (right click the project > Run As… > maven install).

Add Project to Open Liberty

Go to:

Servers > “WebSphere Application Server Liberty” > Right Click “Add and Remove…”.

>> Move our javaee8 application from Available to Configured.

>> Press Finish.

Start Open Liberty

>> Servers > “WebSphere Application Server Liberty” > Right Click “Start”.

You will get an error message about setting a keystore. I am just cancelling this as it is used by the “local connector” feature. I’ve not found a way to clear this error on Eclipse – but will post when I have.

The server will start and you can access the pre-installed application on:

http://localhost:9080/javaee8/resources/ping

Woohoo running Java 9 on Java EE 8 Open Liberty!!!

Conclusion

This post uses Adam Bien’s approach to running Java 9 on Java EE 8 Open Liberty – but demonstrates how you can integrate this into Eclipse Oxygen. The next post will build on this archetype to create a simple JSF 2.3 application.

Finally I think it is great to see the progress being made to provide Java EE 8 on Java 9, and would like to thank the developers involved in this work.


This post was written by a Martin Farrell, and first appeared Here. Martin Farrel is an independent Java Consultant and trainer based in Edinburgh, UK, with over 18 years Java experience. He has consulted across a range of businesses from banking to telecommunications, and Silicon Valley start-ups. He blogs about Java and Spring technologies on the popular www.javabullets.com blog, and is Most Valuable Blogger at dzone.com and a contributor to javacodegeeks.com.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s