[2.0.3 Java] how to include database driver JAR file

793 views
Skip to first unread message

Chris B.

unread,
Sep 30, 2012, 12:37:45 AM9/30/12
to play-fr...@googlegroups.com
I placed PostgreSQL database driver JAR file (postgresql-9.1-902.jdbc4.jar) into a "lib" folder under project root folder. And specify dependency in Build.scala as this:
val appDependencipes = Seq(
      // Add your project dependencies here
      "postgresql" % "postgresql" % "9.1-902.jdbc4"
    )

This is working fine in Play 2.0.2. Once I upgraded to 2.0.3, my project broke. It would not build. I got this error when do "play run" in command window and it stop processing.

[warn]  :::::::::::::::::::::::::::::
:::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: postgresql#postgresql;9.1-902.jdbc4: not found

What's wrong here? Did 2.0.3 changed the way external JAR file are included to the project? How to include it now?

Khalid Alkassoum

unread,
Sep 30, 2012, 7:46:24 AM9/30/12
to play-fr...@googlegroups.com
if the jar file is in lib there's no need to reference it in Build.scala.
don't forget to reload the project after putting the driver in lib

Chris B.

unread,
Sep 30, 2012, 12:00:25 PM9/30/12
to play-fr...@googlegroups.com
I got this error if I don't specify dependency in Build.scala:

[PersistenceException: The default EbeanServer has not been defined? This is normally set via the ebean.datasource.default property. Otherwise it should be registered programatically via registerServer()]

The error is complaining this line of code: Transaction trans = Ebean.beginTransaction();

I have set database settings in application.conf like this:

db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgresql://localhost:5432/testdb"
db.default.user="xxuser"
db.default.password="xxpwd"

Are you sure there is no need to add the dependency in Build.scala? Right now, I put the driver JAR in the "lib" folder. Is this the only way to include the external JAR into build? How come this works in Play 2.0.2, but not in 2.0.3?

virtualeyes

unread,
Sep 30, 2012, 12:07:30 PM9/30/12
to play-fr...@googlegroups.com
could be wrong, but I believe you need to let sbt know the lib location in your Build.scala Project settings block:

unmanagedBase <<= baseDirectory { base => base / "/lib" }

that, or figure out why this:

"postgresql" % "postgresql" % "9.1-902.jdbc4"

is not resolving

Chris B.

unread,
Sep 30, 2012, 1:17:10 PM9/30/12
to play-fr...@googlegroups.com
Putting that line ( unmanagedBase <<= baseDirectory { base => base / "/lib" } ) to Build.scala did not help. Looks like it still can not find the lib.


[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: postgresql#postgresql;9.1-902.jdbc4: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[error] {file:/C:/testproj/}testproj/*:update: sbt.ResolveException: unresolved dependency: postgresql#postgresql;9.1-902.jdbc4: not found

here is my Build.scala:

import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

    val appName         = "testproj"
    val appVersion      = "1.0-SNAPSHOT"

 
 
    val appDependencies = Seq(
      // Add your project dependencies here,

      "postgresql" % "postgresql" % "9.1-902.jdbc4"
    )
   
    val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
      // Add your own project settings here    
       unmanagedBase <<= baseDirectory { base => base / "/lib" }
    )

}

What should I look into next? How to figure out why the dependency is not resolving?

Marcos Pereira

unread,
Sep 30, 2012, 11:28:31 PM9/30/12
to play-fr...@googlegroups.com
Apparently, the sonatype repository does not contains this version of Postgres driver. The last version there is 9.1-901-jdbc4.

Try this version and see if it works for you.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/mBxXEQxw0fUJ.

To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Chris B.

unread,
Oct 1, 2012, 10:28:38 PM10/1/12
to play-fr...@googlegroups.com
Why does Play try to get the PostgreSQL driver from repository when there is a local copy of the driver in the "lib" folder? How can I specify Play to reference the driver in the "lib" folder instead and not to bother with the repository lookup? Thanks.

Brennan Saeta

unread,
Nov 26, 2012, 11:32:36 AM11/26/12
to play-fr...@googlegroups.com, davi...@gmail.com
I think that you don't need to include the line in appDependencies if you just dropped the Jar into the lib folder. Those are for managed dependencies. Best, -Brennan


On Sun, Nov 25, 2012 at 9:56 PM, Alexandros Bantis <amba...@gmail.com> wrote:
I'm in the same situation as Chris B. I have postgres 9.2 on my system, I'm learning play and I would prefer not to downgrade postgres. I'm not familiar with ant and ivy. Could you explain how to convert the jar into a format that play can read (I assume that I place the files into ../play-2.0.4/repository/cache/ I tried dropping it into a /lib directory and adding the lines suggested by virtualeyes, and am recieving the same errors in trying to use 9.2-1002.jdbc4
thanks,

On Sunday, September 30, 2012 3:28:49 PM UTC-7, Arato wrote:
AFAIK there is no public repository for  "9.1-902.jdbc4" yet. In Lift I used to use my own local repository for that. Now I am playing with the last snapshots for 9.2 driver. I am a complete newbie in Play! -I do not know absolutely anything about Play! yet-, but I have just dropped the correspondant jars (I compiled with ant) and ivy in the local repository inside Play 2.0, and the Postgresql 9.2 jdbc driver works smoothly in my case.
Best regards. 

--
 
 

Richard Walker

unread,
Jan 7, 2014, 3:47:16 PM1/7/14
to play-fr...@googlegroups.com, davi...@gmail.com
I'm having the same problem discussed here--except it's the org.postgis.jar that Play refuses to see though it is inside the /lib dir. Ironically, it sees the postgresql.jar just fine there in the /lib jar. I've been searching for two hours and have not found the solution to this problem...Any further suggestions?


On Sunday, November 25, 2012 9:56:13 PM UTC-8, Alexandros Bantis wrote:
I'm in the same situation as Chris B. I have postgres 9.2 on my system, I'm learning play and I would prefer not to downgrade postgres. I'm not familiar with ant and ivy. Could you explain how to convert the jar into a format that play can read (I assume that I place the files into ../play-2.0.4/repository/cache/ I tried dropping it into a /lib directory and adding the lines suggested by virtualeyes, and am recieving the same errors in trying to use 9.2-1002.jdbc4
thanks,

On Sunday, September 30, 2012 3:28:49 PM UTC-7, Arato wrote:
AFAIK there is no public repository for  "9.1-902.jdbc4" yet. In Lift I used to use my own local repository for that. Now I am playing with the last snapshots for 9.2 driver. I am a complete newbie in Play! -I do not know absolutely anything about Play! yet-, but I have just dropped the correspondant jars (I compiled with ant) and ivy in the local repository inside Play 2.0, and the Postgresql 9.2 jdbc driver works smoothly in my case.
Best regards. 

On Sunday, September 30, 2012 6:37:46 AM UTC+2, Chris B. wrote:

Michael Hawkins

unread,
May 7, 2014, 12:09:39 AM5/7/14
to play-fr...@googlegroups.com
I had the same problem when I tried to include the following line in build.sbt in the project root.

libraryDependencies += "postgresql" %% "postgresql" % "postgresql-9.2-1004.jdbc41"

My environment
  • Activator 1.1.2
  • Play 2.2.3 / Scala 2.10.3 / Java 1.7.0_51 hence the reason for jdbc41 below
  • postgresql-9.3-1101.jdbc41.jar  downloaded from http://jdbc.postgresql.org/download.html
  • MBP running mavericks
The solution as Brennan suggested was to remove the libraryDependencies for postgresql (see above) and put the postgres jar file into a lib folder off of root. Worked like a charm. 

Thanks Brennan and community

Donovan Muller

unread,
May 7, 2014, 3:33:30 AM5/7/14
to play-fr...@googlegroups.com
Hi Michael,

The dependency is: 

libraryDependencies += "org.postgresql" % "postgresql" % "9.2-1004-jdbc41"


Also the double '%%' is useful for Scala libs and appends the Scala version is use automatically: http://www.scala-sbt.org/release/docs/Getting-Started/Library-Dependencies.html#getting-the-right-scala-version-with
Reply all
Reply to author
Forward
0 new messages