Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 637
Sotirios Delimanolis Avatar asked Nov 05 '12 23:11

Sotirios Delimanolis


People also ask

How do I add a dependency in Maven?

Add a Java Maven Dependency to the Utility ProjectRight-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.


2 Answers

PostgreSQL drivers jars are included in Central Repository of Maven:

  • List of included versions of PostgreSQL drivers.

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)

like image 119
madth3 Avatar answered Oct 21 '22 22:10

madth3


Updating for latest release:

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

Source

Hope it helps!

like image 31
facundofarias Avatar answered Oct 22 '22 00:10

facundofarias