Getting Started with Eclipse MicroProfile, Part 4: OpenLiberty
Having looked at Thorntail last time, we’ll take a look at OpenLiberty this time. OpenLiberty is the open source project under which, as I understand the state of things, IBM’s WebSphere Liberty is developed. In this installment, we’ll give its MicroProfile support a quick spin.
There is a lot going on there, but, as best as I can tell, we’re using the OpenLiberty Maven plugin to extract the OpenLiberty server, add our app to it, then package it back up. It works, but it takes a lot of work to get there. :)
Before we can build, though, we do need to create one file to configure the OpenLiberty instance. That lives at src/main/liberty/config/server.xml:
This tells OpenLiberty that we want to enable MicroProfile 2.0, what ports we want to listen on, what application to deploy, and its context root.
Once that’s done, we can run our app:
# mvn install
# java -jar target/openliberty.jar
[AUDIT ] CWWKT0016I: Web application available (default_host): http://jdlee:8080/
# curl http://localhost:8080
# curl http://localhost:8080/?name=OpenLiberty
Just as expected. Before closing out this installment, though, a word on testing.
With the last two implementations, I was able to provide an Arquillian-based set of tests. Technically, I think OpenLiberty can be tested with Arquillian, but I was unable to make it work. Obviously, if this were a production project, I’d figure it out, but I took the easy way out here. :) However, in the OpenLiberty docs, they had some extra execution configurations for the plugin that starts and stops the server for integration tests, so I went with that. During the build, then, the server is started, the tests (which are just HTTP client calls to the server) run, and the server is shutdown. Not as nice as Arquillian, but it works in a pinch.
We start by configuring the surefire plugin to not run during the test phase, then configure the failsafe plugin to run during the integration-test phase. Finally, we set up executions for the liberty-maven-plugin to start and stop the server in the pre-integration-test and post-integration-test phases. There are likely a myriad of ways to handle that, so feel free to pick your favorite. This should get you going, though.
# mvn install
[INFO] --- maven-failsafe-plugin:2.22.1:integration-test (integration-tests) @ openliberty ---
[INFO] T E S T S
[INFO] Running com.steeplesoft.microprofile.openliberty.test.OpenLibertyTest
Connecting to http://localhost:8080/?name=OpenLiberty
Connecting to http://localhost:8080/
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.726 s - in com.steeplesoft.microprofile.openliberty.test.OpenLibertyTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO] --- liberty-maven-plugin:2.2:test-stop-server (stop-server) @ openliberty ---
Like I said. It’s not the most elegant, but it should get you going, and with that, we’re done! In the next installment, well see what it takes to get MicroProfile and Apache TomEE up and running.
You can find the source for the whole project here, and for this part here.
Twitter user gcharters contacted me to tell me about a parent POM that OpenLiberty users can use to avoid some of the boilerplate above. You can find that POM here and cut the size of your POM significantly. Enjoy!