Configuring Database Connections

21 views
Skip to first unread message

Shawn Sparks

unread,
Feb 19, 2011, 2:28:02 PM2/19/11
to Iowa Scala Enthusiasts
I posted this question on Stack Overflow a couple days ago, but I have
not seen an answer that addresses what I am really asking. Hopefully
someone in this group can help me.

http://stackoverflow.com/questions/5024499/scala-lift-database-connections

So far all the answers are about using a properties file managed with
your project. Using Maven profiles, different properties files can be
selected at build time. However, I'd like it so I could build the app
and distribute it. Those receiving the compiled version could use
their own file that they have at least some control over where it
exists. If you see my comments on the first answer, you can get a
little more details.

Zach Cox

unread,
Feb 20, 2011, 2:57:16 PM2/20/11
to iowa-scala-...@googlegroups.com, Shawn Sparks
Have you tried the update to the 1st answer, where he uses Props.whereToLook?

Shawn Sparks

unread,
Feb 20, 2011, 3:25:06 PM2/20/11
to iowa-scala-...@googlegroups.com
As I added in my 2nd comment to the answer, I am then curious where to
put the file I pull in. In the PHP world, the user controls where it
would go based on the directory they place the rest of the PHP files for
the app. In the Java/Scala world, would this go in the workdir
somewhere? I was messing around with Hudson/Jenkins last night which
uses an environment variable to define where its file database and
workspaces are stored. Is this common?

Zach Cox

unread,
Feb 21, 2011, 8:17:05 AM2/21/11
to iowa-scala-...@googlegroups.com
So you want to distribute a .war file to users that they can just drop
into a servlet container and run?

I think the Hudson/Jenkins approach of configuring a webapp's
parameters using an environment variable should be fine.

System properties would be another good way to do this. That's how
you set the run mode in Lift:

http://www.assembla.com/wiki/show/liftweb/Run_Modes

So you could either set the DB connection params in the env var/sys
prop directly, or that's where you could let the user specify the
location of the Lift .props files.

Wade Arnold

unread,
Feb 21, 2011, 5:29:02 PM2/21/11
to iowa-scala-...@googlegroups.com
If you are deploying inside of tomcat then you configure the servlet container to make the connection to the DB. This is one of the reasons you use an app server something that is not comparable to PHP. In PHP the driver is what is doing the abstraction and connection pooling. 

Two approaches for LIFT. 


We have been really enjoying squeryl in both lift and pure scala apps. It creates better queries than lifts mapper and is type safe all the way to the data store. It's like what ORM was suppose to be. 


--
Wade....@T8Webware.com
CEO T8 Webware
877.884.3327 x105
900 Technology pkwy, Suite 200
Cedar Falls, Iowa
@wadearnold
linkedin.com/in/wadearnold

Zach Cox

unread,
Feb 22, 2011, 1:25:49 PM2/22/11
to iowa-scala-...@googlegroups.com
Wade is right: if you intend your .war to be deployed in a container,
configure your Lift app in Boot to use JNDI, then your end-users can
configure the db params in their container using JNDI. Let me know if
you want sample code & Tomcat-specific config for JNDI.
Reply all
Reply to author
Forward
0 new messages