by mortenterhart

GitHub Readme.md

Heroku WildFly PostgreSQL Buildpack

Heroku Elements Buildpack Registry Latest GitHub Release

This is a Heroku Buildpack for adding a PostgreSQL Driver and Datasource to an existing Wildfly AS.

This buildpack is intended to be used in conjunction with the Wildfly Buildpack.

Standalone Usage

Using with the Java and Wildfly Buildpacks

You can use the standard Heroku Java buildpack for creating a WAR file, the Wildfly buildpack for downloading and installing a Wildfly instance and this buildpack to add a driver and a datasource for the official Heroku PostgreSQL addon. The addon is automatically provisioned with the free hobby-dev plan for your application by this buildpack.

heroku buildpacks:clear
heroku buildpacks:add heroku/java
heroku buildpacks:add mterhart/wildfly
heroku buildpacks:add mterhart/wildfly-postgresql

This buildpack depends on the Wildfly buildpack that installs the Wildfly server in the requested version to the correct location. So make sure to add the buildpacks in the correct order.

Usage from a Buildpack

mkdir -p /tmp/wildfly-postgresql-buildpack
curl --retry 3 --silent --location "${WILDFLY_POSTGRESQL_BUILDPACK_URL}" | tar xzm -C /tmp/wildfly-postgresql-buildpack --strip-components=1

source /tmp/wildfly-postgresql-buildpack/lib/postgresql_driver.sh
source /tmp/wildfly-postgresql-buildpack/lib/postgresql_datasource.sh

Specifying a specific Revision of the Buildpack

You can use another revision of this buildpack for your own one. Simply change the buildpack URL and append a version specifier to the filename, for example v15. Then change the line in your script to the following:



Config Vars

 Name Default Value Description DATASOURCE_NAME appDS The name of the PostgreSQL datasource DATASOURCE_JNDI_NAME java:jboss/datasources/appDS The JNDI name of the persistence unit defined in persistence.xml. Overrides the value automatically read from persistence.xml. SKIP_DATASOURCE false When set to true this buildpack will only install the driver and skip the datasource creation for WildFly. POSTGRESQL_DRIVER_NAME postgresql WAR_PERSISTENCE_XML_PATH unset JBOSS_HOME automatically set The path to the WildFly home directory HIBERNATE_DIALECT_AUTO_UPDATE true When set to true the auto update for the Hibernate dialect in the persistence.xml is disabled. HIBERNATE_DIALECT org.hibernate.dialect.PostgreSQL95Dialect The Hibernate dialect that is automatically updated BUILDPACK_DEBUG false When set to true the buildpack will produce more output including executed commands, values of variables and time measurements. When creating the datasource, the username, password and connection URL will be hidden with ***** in the output. Warning: This option should only be used for testing your build and not for production. It is possible that sensitive data gets printed to the logs.

Configuring the Wildfly version

Create a system.properties file in the root directory of your project and set the wildfly.version property as follows:


This is necessary because the buildpack needs to know the location of the Wildfly installation directory.

PostgreSQL Driver

The buildpack downloads the PostgreSQL JDBC Driver Version 42.2.1 and adds it to the Wildfly server as a module first. The driver is then installed at the Wildfly server.

Configuring the PostgreSQL Datasource

By default, the buildpack looks for the file src/main/resources/META-INF/persistence.xml to determine the JNDI name and datasource name used by the project. A new datasource matching these names is then added to the Wildfly server.

An example for a valid persistence.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"

    <persistence-unit name="app" transaction-type="JTA">
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/>
            <property name="hibernate.transaction.manager_lookup_class"
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>

The value inside the <jta-data-source> tag is used as JNDI name and the name of the persistence unit including a trailing DS is used as name for the new datasource.

Auto-updating the Hibernate Dialect

When using Hibernate as a JPA provider like in the example above the buildpack changes the Hibernate Dialect automatically to PostgreSQL. This is done by replacing the given value in the persistence.xml.