Published on 19.2.2026

GeoServer + PostgreSQL + Jetty + JNDI  – impossible equation?

JNDI (Java Naming and Directory Interface) connections provide an excellent way to enhance communication between GeoServer and PostgreSQL. By enabling multiple data stores to share the same connection pool, database usage becomes more efficient and scalable.

Setting up a JNDI connection pool isn’t too complex. Especially if your GeoServer instance is running on Tomcat, you can easily find step-by-step guides for that setup. But what if you are using some other servlet container?

In the case of this blog post, the starting point isn’t the easiest. GeoServer was hastily installed using the platform-independent binary. It then became an important production server until you discovered that the connections to your database could no longer be handled without pooling. Does this mean you need to redesign your entire system and switch to Tomcat? The simple answer is no.

So, we start with GeoServer bundled inside Jetty, a setup that doesn’t include JNDI connection support out of the box. Depending on your configuration, your situation may differ, but it’s unlikely to be more complex. In our case, we use GeoServer 3.0 bundled with Jetty 12.1.3. (Yes, we know that 3.0 isn’t a stable version yet but soon it will be.)

1. Let’s add the necessary JAR files to our Jetty installation.

The files should be copied to the ‘/lib/ext/’ directory.

  • jetty-jndi-12.1.3.jar
  • jetty-plus-12.1.3.jar

The JNDI resources are part of the Jetty Plus module. The JAR files can be downloaded from Maven Central at https://repo1.maven.org/maven2/org/eclipse/jetty/

  • postgresql-42.7.9.jar

We also need a JDBC driver for PostgreSQL, which communicates with the database using the PostgreSQL native network protocol. We can download the JAR file from https://jdbc.postgresql.org/. The driver version must match the Java version in use.

  • HikariCP-7.0.2.jar

The PostgreSQL JDBC driver itself does not support connection pooling. For pooling, we need an external library, such as HikariCP. HikariCP is said to be a “zero-overhead” production-ready JDBC connection pool. The HikariCP version has to match the Java version in use. The HikariCP JAR file can be downloaded from the Maven Central at https://repo1.maven.org/maven2/com/zaxxer/HikariCP/

These JAR files need to be specified in the ‘start.ini’ file to ensure they are loaded when Jetty starts.

--lib=lib/ext/HikariCP-7.0.2.jar
--lib=lib/ext/jetty-jndi-12.1.3.jar
--lib=lib/ext/jetty-plus-12.1.3.jar
--lib=lib/ext/postgresql-42.7.9.jar

2. Defining the connection pool

We define the JNDI resource in ‘jetty.xml’. This allows the same configuration to be used across all applications running on this Jetty instance.

<New id="jdbcPostGIS" class="org.eclipse.jetty.plus.jndi.Resource">
    		<Arg>jdbc/gisdb</Arg>
    		<Arg>
        		<New class="com.zaxxer.hikari.HikariDataSource">
            	<Set name="jdbcUrl">jdbc:postgresql://localhost:5432/gis_database</Set>
    		<Set name="driverClassName">org.postgresql.Driver</Set>
            	<Set name="username">gis_database</Set>
            	<Set name="password">gistest</Set>
            	<Set name="maximumPoolSize">80</Set>
           		</New>
    		</Arg>
	</New>

The block creates a resource with two arguments. The first argument defines the name for the resource, which is the name the applications will use to look up this data source. We have chosen the name ‘jdbc/gisdb’. The second argument is a new instance of the ‘HikariDataSource’ class that gets the parameters needed for establishing the connection.

3. Restarting Jetty

4. Creating the data store in GeoServer

This final step isn’t related to Jetty. Now, we can create the data store in GeoServer just as we would if the connection pool had been defined in Tomcat.

We select ‘PostGIS (JNDI)’ from the data source list, and then fill out the form as follows.

GeoServer

Note that the ‘jndiReferenceName’ is the name we set as the first argument for the resource in step 2. In this example, it’s ‘jdbc/gisdb’. You can also specify the schema here.

That’s all that’s needed. We can now create layers from our newly created data source. Please note that this configuration has not been tested in production environments. Feel free to comment if you find any issues or know of a better configuration for PostgreSQL and JNDI in Jetty. If you are still using GeoServer 2, as you most likely do, a small extra trick may be needed. But that’s a different story. An update to GeoServer 3 is waiting anyway.

Profiilikuva

Ismo Lahtinen

Ismo, M.Sc.(Tech.) is a geomatics professional with more than ten years experience in geographic information systems in the public sector. Additionally, he has even a longer experience in programming both in work and as a hobby.