

PostgreSQL on Open Liberty - Sebastian Daschner
source link: https://blog.sebastian-daschner.com/entries/openliberty-with-postgres
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

PostgreSQL on Open Liberty
PostgreSQL on Open Liberty
sunday, january 28, 2018Open Liberty is an interesting new OSS Java EE application server that originated from WebSphere Liberty. You can configure Open Liberty to use PostgreSQL as its default data source as follows:
Add directives for <datasource>
, <jdbcDriver>
, and <library>
to the server.xml
configuration:
<?xml version="1.0" encoding="UTF-8"?>
<server description="OpenLiberty Java EE 8 Server">
<featureManager>
<feature>javaee-7.0</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443"/>
<keyStore id="defaultKeyStore" password="Liberty"/>
<!-- Postgres coffee-shop-db definition -->
<dataSource id="DefaultDataSource"
jndiName="jdbc/sample"
jdbcDriverRef="postgresql-driver"
type="javax.sql.ConnectionPoolDataSource"
transactional="true">
<properties serverName="coffee-shop-db"
portNumber="5432"
databaseName="postgres"
user="postgres"
password="postgres"/>
</dataSource>
<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/ol/wlp/lib"
includes="postgresql-9.4-1201.jar"/>
</library>
</server>
The database available via host coffee-shop-db
will be accessed through the default Postgres port 5432
with postgres
as database name, username and password.
The driver library, here postgresql-9.4-1201.jar
, needs to reside in the lib/
directory of the server installation.
The default data source can be used transparently from a Java EE application.
Only a single persistence unit needs to be specified in the persistence.xml
file, similar to the following snippet:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="prod" transaction-type="JTA"/>
</persistence>
If the application comprises multiple databases, the persistence units are required to specify the JNDI names of their corresponding data source.
Tested with the official Docker image open-liberty:javaee7
.
Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java:
All opinions are my own and do not reflect those of my employer or colleagues.
© Sebastian Daschner, CC BY-NC-SA 4.0
Recommend
-
121
An IBM Open Source Project
-
165
Dockerized Java EE 8 applications with GlassFish 5.0 Dockerized Java EE 8 applications with GlassFish 5.0
-
68
It's been a long time since my last blogpost, but I'm back with a post about how to use your Yubikey 4 for GPG and SSH keys. What is a Yubikey? The rather small Yub...
-
119
Laravel 5.6 adds the ability to register alias directives for Blade components. Let's review some background information and examples.
-
62
Server side rendering is a hot topic when it comes to client side applications. Unfortunately, it's not an easy thing to do, especially if you're not building things in a Node.js environment.I published two libraries to enable server side render...
-
65
Let’s imagine you start working on a new project for your customer. The mission: Build a machine that is able to estimate the amount of beer drunk by an crowd by processing an image of the crowd. You…
-
54
“We'll publish critical vulnerabilities in PGP/GPG and S/MIME email encryption on 2018-05-15 07:00 UTC. They might reveal the plaintext of encrypted emails, including encrypted emails sent in the past. #efail 1/4”
-
57
Performance is one of the most important and most complex tasks when managing a database. It can be affected by the configurat...
-
45
This month we are spending some time talking about the importance ofdatabase monitoring and auditing of your database environm...
-
6
Moving from WebSphere Liberty to Open Source Open Liberty is a modular open source Java runtime. WebSphere Liberty is IBM’s commercial offering based on Open Liberty. There are reasons why you should consider using O...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK