javahibernatepostgresqlmaven

How do you add PostgreSQL Driver as a dependency in Maven?


I'm trying to develop a Java application with Maven while using Hibernate with a PostgreSQL database for persistence. I don't understand how I'm supposed to connect the PostgreSQL drivers to my application. I get that you add dependencies in Maven's pom.xml file, which finds jars from a remote repository, but what about other jars?


Solution

  • PostgreSQL drivers jars are included in Central Repository of Maven:

    For PostgreSQL up to 9.1, use:

    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>VERSION</version>
    </dependency>
    

    or for 9.2+

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>VERSION</version>
    </dependency>
    

    (Thanks to @Caspar for the correction)