title: How to add Postgres Driver to Open Liberty?
body: <p>I am implementing a basic REST API with Micorprofile 3.2 and deploying it with Open Liberty.</p>
  
  <p>The server.xml,</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;server description="${project.name}"&gt;
  
      &lt;featureManager&gt;
          &lt;feature&gt;microProfile-3.2&lt;/feature&gt;
          &lt;feature&gt;jpa-2.2&lt;/feature&gt;
          &lt;feature&gt;jdbc-4.2&lt;/feature&gt;
          &lt;feature&gt;jndi-1.0&lt;/feature&gt;
      &lt;/featureManager&gt;
  
      &lt;httpEndpoint id="defaultHttpEndpoint"
                    host="*"
                    httpPort="8080"
                    httpsPort="9443"/&gt;
  
      &lt;webApplication location="${project.name}.war" contextRoot="/"/&gt;
      &lt;mpMetrics authentication="false"/&gt;
  
      &lt;dataSource id="DefaultDataSource"
                  jndiName="jdbc/postgresql"&gt;
          &lt;jdbcDriver jdbcDriverRef="postgresql-driver" libraryRef="postgresql-library"/&gt;
          &lt;properties.postgres serverName="localhost"
                               portNumber="5432"
                               databaseName="postgres"
                               user="postgres"
                               password="postgres"/&gt;
      &lt;/dataSource&gt;
  
      &lt;jdbcDriver id="postgresql-driver"
                  javax.sql.XADataSource="org.postgresql.xa.PGXADataSource"
                  javax.sql.ConnectionPoolDataSource="org.postgresql.ds.PGConnectionPoolDataSource"
                  libraryRef="postgresql-library"/&gt;
  
      &lt;library id="postgresql-library"&gt;
          &lt;fileset id="PostgreSQLFileset" dir="${shared.resource.dir}/jdbc"
                   includes="postgresql-42.2.9.jar"/&gt;
      &lt;/library&gt;
  &lt;/server&gt;
  
  </code></pre>
  
  <p>my persistence.xml,</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"
               version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"&gt;
  
      &lt;persistence-unit name="jpa-unit" transaction-type="JTA"&gt;
          &lt;jta-data-source&gt;jdbc/postgresql&lt;/jta-data-source&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  
  </code></pre>
  
  <p>The problem is everytime i try to use a EntityManager i get the following error:</p>
  
  <pre><code>[INFO] [ERROR   ] CWWJP0015E: An error occurred in the org.eclipse.persistence.jpa.PersistenceProvider persistence provider when it attempted to create the container entity manager factory for the jpa-unit persistence unit. The following error occurred: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.7.5.v20191016-ea124dd158): org.eclipse.persistence.exceptions.EntityManagerSetupException
  [INFO] Exception Description: Predeployment of PersistenceUnit [jpa-unit] failed.
  [INFO] Internal Exception: javax.persistence.PersistenceException: CWWJP0013E: The server cannot locate the java:comp/DefaultDataSource data source for the jpa-unit persistence unit because it has encountered the following exception: javax.naming.NamingException [Root exception is java.sql.SQLNonTransientException: DSRA4000E: No implementations of [javax.sql.XADataSource, javax.sql.ConnectionPoolDataSource, javax.sql.DataSource, java.sql.Driver] are found for dataSource[DefaultDataSource] with library postgresql-library. The name or location of JDBC driver JAR files might be incorrect or inaccessible. Searched in: []. Searched under packages: [].].
  [INFO] [ERROR   ] CWOWB1000E: A CDI error has occurred: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/xx.xx.demo.micro.pq.infrastructure.infrastructure.EntityManagerProducer/entityManagerFactory reference.  The exception message was: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.7.5.v20191016-ea124dd158): org.eclipse.persistence.exceptions.EntityManagerSetupException
  [INFO] Exception Description: Predeployment of PersistenceUnit [jpa-unit] failed.
  [INFO] Internal Exception: javax.persistence.PersistenceException: CWWJP0013E: The server cannot locate the java:comp/DefaultDataSource data source for the jpa-unit persistence unit because it has encountered the following exception: javax.naming.NamingException [Root exception is java.sql.SQLNonTransientException: DSRA4000E: No implementations of [javax.sql.XADataSource, javax.sql.ConnectionPoolDataSource, javax.sql.DataSource, java.sql.Driver] are found for dataSource[DefaultDataSource] with library postgresql-library. The name or location of JDBC driver JAR files might be incorrect or inaccessible. Searched in: []. Searched under packages: [].].
  [INFO] [ERROR   ] CWOWB1000E: A CDI error has occurred: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/xx.xx.demo.micro.pq.infrastructure.infrastructure.EntityManagerProducer/entityManagerFactory reference.  The exception message was: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.7.5.v20191016-ea124dd158): org.eclipse.persistence.exceptions.EntityManagerSetupException
  [INFO] Exception Description: Predeployment of PersistenceUnit [jpa-unit] failed.
  [INFO] Internal Exception: javax.persistence.PersistenceException: CWWJP0013E: The server cannot locate the java:comp/DefaultDataSource data source for the jpa-unit persistence unit because it has encountered the following exception: javax.naming.NamingException [Root exception is java.sql.SQLNonTransientException: DSRA4000E: No implementations of [javax.sql.XADataSource, javax.sql.ConnectionPoolDataSource, javax.sql.DataSource, java.sql.Driver] are found for dataSource[DefaultDataSource] with library postgresql-library. The name or location of JDBC driver JAR files might be incorrect or inaccessible. Searched in: []. Searched under packages: [].].
  [INFO] [WARNING ] CWMOT0009W: The OpenTracing exception mapper detected and is handling an unhandled exception from the JAX-RS application. 
  [INFO]                                                                                                                java.lang.NullPointerException
  [INFO]  at xx.xx.demo.micro.pq.infrastructure.infrastructure.EntityManagerProducer.createEntityManager(EntityManagerProducer.java:21)
  [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  [INFO]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  [INFO]  at java.lang.reflect.Method.invoke(Method.java:498)
  [INFO]  at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95)
  [INFO]  at [internal classes]
  [INFO]  at org.jboss.weldx.persistence.EntityManager$1152902288$Proxy$_$$_WeldClientProxy.getCriteriaBuilder(Unknown Source)
  [INFO]  at xx.xx.demo.micro.pq.domain.ProductRepository.findAll(ProductRepository.java:42)
  [INFO]  at xx.xx.demo.micro.pq.domain.ProductRepository$Proxy$_$$_WeldClientProxy.findAll(Unknown Source)
  [INFO]  at xx.xx.demo.micro.pq.application.ProductResource.getAllProduct(ProductResource.java:54)
  [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  [INFO]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  [INFO]  at java.lang.reflect.Method.invoke(Method.java:498)
  [INFO]  at com.ibm.ws.jaxrs20.cdi.component.JaxRsFactoryImplicitBeanCDICustomizer.serviceInvoke(JaxRsFactoryImplicitBeanCDICustomizer.java:304)
  [INFO]  at [internal classes]
  </code></pre>
  
  <p>I create the EntityManager the following way:</p>
  
  <pre class="lang-java prettyprint-override"><code>  @(unitName = "jpa-unit")
    private EntityManagerFactory entityManagerFactory;
  
    @Produces
    @RequestScoped
    public EntityManager createEntityManager() {
      return entityManagerFactory.createEntityManager();
    }
  </code></pre>
  
  <p>I dont really understand why open liberty looks in here: <code>Searched in: []. Searched under packages: [].].
  </code></p>
  
  <p>EDIT: add pom.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
           xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;xx.xxx&lt;/groupId&gt;
      &lt;artifactId&gt;demo-micro-pq&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;properties&gt;
          &lt;openliberty.maven.version&gt;3.1&lt;/openliberty.maven.version&gt;
          &lt;final.name&gt;demo-micro-pq&lt;/final.name&gt;
          &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
          &lt;openliberty.version&gt;[19.0.0.9,)&lt;/openliberty.version&gt;
          &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
          &lt;version.javaee&gt;8.0.1&lt;/version.javaee&gt;
          &lt;version.slf4j&gt;1.7.28&lt;/version.slf4j&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.eclipse.microprofile&lt;/groupId&gt;
              &lt;artifactId&gt;microprofile&lt;/artifactId&gt;
              &lt;version&gt;3.2&lt;/version&gt;
              &lt;type&gt;pom&lt;/type&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax&lt;/groupId&gt;
              &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
              &lt;version&gt;${version.javaee}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;5.4.10.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;5.4.10.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
              &lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;
              &lt;version&gt;3.9&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
              &lt;version&gt;${version.slf4j}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;jcl-over-slf4j&lt;/artifactId&gt;
              &lt;version&gt;${version.slf4j}&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;finalName&gt;demo-micro-pq&lt;/finalName&gt;
      &lt;/build&gt;
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;liberty&lt;/id&gt;
              &lt;activation&gt;
                  &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
              &lt;/activation&gt;
              &lt;build&gt;
                  &lt;plugins&gt;
                      &lt;plugin&gt;
                          &lt;groupId&gt;io.openliberty.tools&lt;/groupId&gt;
                          &lt;artifactId&gt;liberty-maven-plugin&lt;/artifactId&gt;
                          &lt;version&gt;${openliberty.maven.version}&lt;/version&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;id&gt;package-server&lt;/id&gt;
                                  &lt;phase&gt;package&lt;/phase&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;create&lt;/goal&gt;
                                      &lt;goal&gt;install-feature&lt;/goal&gt;
                                      &lt;goal&gt;deploy&lt;/goal&gt;
                                      &lt;goal&gt;package&lt;/goal&gt;
                                  &lt;/goals&gt;
                                  &lt;configuration&gt;
                                      &lt;outputDirectory&gt;target/wlp-package&lt;/outputDirectory&gt;
                                  &lt;/configuration&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                          &lt;configuration&gt;
                              &lt;include&gt;runnable&lt;/include&gt;
                              &lt;serverName&gt;${final.name}&lt;/serverName&gt;
                              &lt;bootstrapProperties&gt;
                                  &lt;project.name&gt;${final.name}&lt;/project.name&gt;
                                  &lt;jwt.issuer&gt;https://server.example.com&lt;/jwt.issuer&gt;
                              &lt;/bootstrapProperties&gt;
                          &lt;/configuration&gt;
                      &lt;/plugin&gt;
                      &lt;plugin&gt;
                          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                          &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
                          &lt;version&gt;3.1.1&lt;/version&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;id&gt;copy&lt;/id&gt;
                                  &lt;phase&gt;package&lt;/phase&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;copy&lt;/goal&gt;
                                  &lt;/goals&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                          &lt;configuration&gt;
                              &lt;artifactItems&gt;
                                  &lt;artifactItem&gt;
                                      &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
                                      &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
                                      &lt;version&gt;42.2.9&lt;/version&gt;
                                      &lt;type&gt;jar&lt;/type&gt;
                                  &lt;/artifactItem&gt;
                              &lt;/artifactItems&gt;
                              &lt;outputDirectory&gt;liberty/wlp/usr/shared/resources&lt;/outputDirectory&gt;
                          &lt;/configuration&gt;
                      &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  &lt;/project&gt;
  </code></pre>