Properties Files and Databases

15 views
Skip to first unread message

Peter Robinett

unread,
Jun 18, 2009, 6:49:02 PM6/18/09
to Lift
Hi all,

I'm looking to switch a basic Lift install to use MySQL. I see that
this has been addressed on the wiki (http://wiki.liftweb.net/index.php/
HowTo_configure_lift_with_MySQL), though it involves hardcoding the
connection details in Boot.scala. I'd like something easier to deploy
to various machines.

The thread following Jörn's announcement of the wiki page on MySQL is
useful (http://groups.google.com/group/liftweb/browse_thread/thread/
bd4e74b68e8aa2a9/9eb2c2ef39442d63) but none of them mention using
properties files, which I understand from this mailing list (e.g.
http://groups.google.com/group/liftweb/browse_thread/thread/49eb17b5dd6fc46a)
is the best way store database settings.

So, I created src/main/resources/props/peter.db.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment></comment>
<entry key="db.driver">com.mysql.jdbc.Driver</entry>
<entry key="db.url">jdbc:mysql://localhost/mydb</entry>
<entry key="db.user">myusername</entry>
<entry key="db.password">mypassword</entry>
</properties>

Unfortunately, the property file does appear to be loaded, as the
DBVendor code in Boot.scala generated by the lift-archetype-basic
archetype falls back to its derby defaults. Do you have any idea what
I'm doing wrong? Not having any experience with Java, I wouldn't be
surprised if it's something as simple as getting the properties XML
wrong...

Thanks for your help!

Peter

David Pollak

unread,
Jun 19, 2009, 12:15:32 AM6/19/09
to lif...@googlegroups.com
If your username is peter, put a file in src/main/resources/props named peter.props

In that file, place the following lines:

db.driver=the_name_name_of_your_driver
db.url=the_url_to_access_your_database
db.user=the_username
db.password=the_db_password
test.me=true

Add the following line to Boot.scala:

println(Props.get("test.me")

When you run your app Full(true) should appear on the console and the correct db settings should be picked up.

Thanks,

David

--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

Peter Robinett

unread,
Jun 19, 2009, 1:02:43 PM6/19/09
to Lift
Thanks, David, that works perfectly. Just for clarification, is the
XML format of Java properties files not supported in Lift?

Peter

On Jun 18, 9:15 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> If your username is peter, put a file in src/main/resources/props named
> peter.props
> In that file, place the following lines:
>
> db.driver=*the_name_name_of_your_driver*
> db.url=*the_url_to_access_your_database*
> db.user=*the_username*
> db.password=*the_db_password*
> test.me=true
>
> **
> **
>
> Add the following line to Boot.scala:
>
> println(Props.get("test.me")
>
> When you run your app Full(true) should appear on the console and the
> correct db settings should be picked up.
>
> Thanks,
>
> David
>
> **
>
> On Thu, Jun 18, 2009 at 3:49 PM, Peter Robinett <pe...@bubblefoundry.com>wrote:
>
>
>
>
>
> > Hi all,
>
> > I'm looking to switch a basic Lift install to use MySQL. I see that
> > this has been addressed on the wiki (http://wiki.liftweb.net/index.php/
> > HowTo_configure_lift_with_MySQL), though it involves hardcoding the
> > connection details in Boot.scala. I'd like something easier to deploy
> > to various machines.
>
> > The thread following Jörn's announcement of the wiki page on MySQL is
> > useful (http://groups.google.com/group/liftweb/browse_thread/thread/
> > bd4e74b68e8aa2a9/9eb2c2ef39442d63) but none of them mention using
> > properties files, which I understand from this mailing list (e.g.
>
> >http://groups.google.com/group/liftweb/browse_thread/thread/49eb17b5d...
> > )
> > is the best way store database settings.
>
> > So, I created src/main/resources/props/peter.db.xml:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
> > <properties>
> >        <comment></comment>
> >        <entry key="db.driver">com.mysql.jdbc.Driver</entry>
> >        <entry key="db.url">jdbc:mysql://localhost/mydb</entry>
> >        <entry key="db.user">myusername</entry>
> >        <entry key="db.password">mypassword</entry>
> > </properties>
>
> > Unfortunately, the property file does appear to be loaded, as the
> > DBVendor code in Boot.scala generated by the lift-archetype-basic
> > archetype falls back to its derby defaults. Do you have any idea what
> > I'm doing wrong? Not having any experience with Java, I wouldn't be
> > surprised if it's something as simple as getting the properties XML
> > wrong...
>
> > Thanks for your help!
>
> > Peter
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890

David Pollak

unread,
Jun 19, 2009, 1:09:44 PM6/19/09
to lif...@googlegroups.com
On Fri, Jun 19, 2009 at 10:02 AM, Peter Robinett <pe...@bubblefoundry.com> wrote:

Thanks, David, that works perfectly. Just for clarification, is the
XML format of Java properties files not supported in Lift?

The current 1.1-SNAPSHOT does support Java's XML properties format, but the naming of the file must be user.props or user.hostname.props or user.runmode.props or user.hostname.runmode.props in order to be found.



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Reply all
Reply to author
Forward
0 new messages