Introduction

Consult System Configuration to get template, some examples and hints for the configuration with JPA.

Current Supported Relational Database

James supports Derby as a default database, you do not need to do any additional configuration if you are using Derby

Spring JPA With Postgres Configuration

If you wish to use Postgres as a database, please follow those steps to configure it

Step 1: Create database on Postgres

You need to install Postgres or run Postgres with Docker

Example to install it on Debian:

          sudo apt-get update && sudo apt-get install postgresql-9.4 postgresql-client-9.4
        

Example to pull and launch Postgres on docker

          docker run --detach --name postgres library/postgres
        

Postgres does not create database on the fly so you need to create the database manually if it does not exist. Here is the command to perform this action:

psql --username postgres --tuples-only --command "SELECT 1 FROM pg_database WHERE dataname = 'database_name'" \
          | grep -q 1 || psql --username postgres --command "CREATE DATABASE database_name"
database_name
The name of database

Step 2: Point to the database in configuration file

Change the content of james-database.properties and point to the 'database_name' created earlier

          database.driverClassName=org.postgresql.Driver
          database.url=jdbc:postgresql://ip_of_postgres/database_name
          database.username=postgres
          database.password=postgres
        

If you are using the James Spring docker image. You need to customise the configuration file of the docker container with those steps:

  • Create a new james-database.properties file with above content
  • Then you can add the configuration file to docker container using --volume flag
  •                 --volume path_to_folder_which_contain_configuration_file/james-database.properties:/root/james-server-app-3.0.0-RC2-SNAPSHOT/conf/james-database.properties
                  

Step 3: Copy driver class to the right place

Follow this link Postgres Driver to download the right version of the JDBC driver.

Copy that jar file to the conf/lib/ folder of Spring James

If you are using the James Spring docker image, download the jar file then make it available on the classpath of your James instance using an additional docker volume:

          --volume path_to_folder_which_contain_jar_file/:/root/james-server-app-3.0.0-RC2-SNAPSHOT/conf/lib/
        

Step 4: Restart James

Follow the guide on Restart and Testing to restart James

If you are using the James Spring docker image, launch James docker or just stop and start docker container again if it ran.

Example to launch James Spring docker image with the volume

          docker run --volume path_to_folder_which_contain_configuration_file/james-database.properties:/root/james-server-app-3.0.0-RC2-SNAPSHOT/conf/james-database.properties \
          --volume path_to_folder_which_contain_jar_file/:/root/james-server-app-3.0.0-RC2-SNAPSHOT/conf/lib/ \
          --hostname localhost --publish "25:25" --publish "110:110" --publish "143:143" --publish "465:465" --publish "587:587" --publish "993:993" \
          --name james_run linagora/james-jpa-spring