Java 9 on Java EE 8 Using Eclipse and Open Liberty
Here we take a look at how to get started with Java 9 using Java EE 8 in Eclipse and Open Liberty for those looking to get started with this combo.
Join the DZone community and get the full member experience.
Join For FreeI wrote a post a few weeks ago titled Which IDE’s and Server’s 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 supporting Java 9 and Java EE 8. These are –
- Payara 5 – for payaradomain
- Open Liberty
Adam Bein posted a video, Java EE 8 on Java 9, on how to deploy a Java 9 application on Open Liberty using netbeans. It's 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.
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 –
Eclipse
Eclipse Oxygen also has Java 9 release available here – I am using the Java EE version of 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'd 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've found for Java EE 8 is also from Adam Bein.
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 straightaway 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 canceling this as its 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!
This post uses Adam Bein’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.
Published at DZone with permission of Martin Farrell, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments