sebastiandaschner blog


Open Liberty Override Configuration

#openliberty wednesday, december 12, 2018

Open Liberty can be easily configured using the server.xml file in it’s config directory. If you’re running your servers in Docker containers you might need to specify multiple levels of configuration, for instance company-internal base images, which might need to define specific properties that are overridden or extended by the applications. Open Liberty offers multiple XML configuration override locations to solve these situations in a practical way.

Besides the obvious server.xml file, there is default configuration which resides under {server.config.dir}/configDropins/defaults/. Files in this directory are applied first.

Next, Open Liberty applies the server.xml file which resides under {server.config.dir}.

If these possibilities aren’t enough, there is also a special override directory, {server.config.dir}/configDropins/overrides/. Configuration files in this location are applied last and might extend or override previously defined properties.

Default and override configuration files are applied in alphabetical order by their file names, and need to have the same format as the server.xml. Please note that the configDropins location doesn’t exist by default and needs to be added manually when you create your own server.

Postgres driver definition

Let’s look at a quick example.

Assuming we want to connect to a Postgres database that we set up as the default datasource. To leverage Docker’s Copy-on-Write file system, we add the Postgres driver in a lower images layer, for example in the base image. That is, the JAR file is added to the server’s lib/ directory, and we define a default configuration …​/defaults/postgres-driver.xml which defines the driver:

<?xml version="1.0" encoding="UTF-8"?>
<server description="OpenLiberty Java EE 8 Server">

  <jdbcDriver id="postgresql-driver"
      javax.sql.XADataSource="org.postgresql.xa.PGXADataSource"
      javax.sql.ConnectionPoolDataSource="org.postgresql.ds.PGConnectionPoolDataSource"
      libraryRef="postgresql-library"/>

  <library id="postgresql-library">
    <fileset id="PostgreSQLFileset" dir="/opt/wlp/lib"
        includes="postgresql-9.4.1212.jar"/>
  </library>

</server>

The JDBC driver in this default configuration can now be used in other configuration locations.

The Docker images of our application defines the datasource with the connection details in the server.xml:

<?xml version="1.0" encoding="UTF-8"?>
<server description="Coffee shop">

  <!-- Postgres coffee-shop-db definition -->
  <dataSource id="DefaultDataSource" jdbcDriverRef="postgresql-driver"
      type="javax.sql.ConnectionPoolDataSource" transactional="true">

    <properties serverName="coffee-shop-db" portNumber="5432"
        databaseName="postgres" user="postgres" password="postgres"/>

  </dataSource>

</server>

Again: we have two Docker images, one base image which ships Open Liberty and includes the postgres-driver.xml and JAR file, and our application image, that adds the server.xml configuration, and, of course, our application.

In this way, the application’s server configuration stays lean and doesn’t need to repeat all defaults that have been made in the company-internal base image.

 

Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java: