Properties file being picked up from Jetty resources directory?

1,798 views
Skip to first unread message

Damian Helme

unread,
May 15, 2012, 7:34:31 AM5/15/12
to lif...@googlegroups.com
Hi,

I was just about to add a line of documentation to the Lift Wiki, but I thought I'd check with the group first whether it's intended (and currently not explicitly documented) or unintended and needs looking at.

I recently noticed that Lift looks in the Jetty resources directory for properties files, and that it looks in the Jetty resources directory AFTER it has looked and not been able to find a props file in the war file. This is due to Lift using getClass.getResourceAsStream to locate props files, which looks on the system classpath.  

The consequences of this are:

1) If your application is picking up the props file from Jetty/resources you can edit the props file without having to recompile the war: great!
2) However, if you have been relying on Lift picking up, say production.default.props, or test.default.props from Jetty/resources, then you need to make sure you then don't add a file of the same name into your war, as if you do, when you deploy the app to jetty it it will pick up war props file rather than the jetty/resources props file. I fell foul of this recently as I had a test.default.props in the war that I was relying on for local unit testing, but then we wanted a different version of test.default.props in the jetty resources directory for system testing. 

So - is this intended and is it worth my adding a note in the documentation?

Thanks

Damian.
---------------------

Maarten Koopmans

unread,
May 15, 2012, 12:07:47 PM5/15/12
to lif...@googlegroups.com
Hi,

Now I'm curious too :-) As it happens, this helps a lot, but even more so if you can reverse it, i.e. Provide default props in a war you distribute, that people can override in the Jetty/resources directory to customize...

--Maarten
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Damian Helme

unread,
Jun 1, 2012, 10:02:18 AM6/1/12
to lif...@googlegroups.com
How about this ...

I've just discovered Props.whereToLook, which prepends to the list of places that Props looks for files.

I also want to solve the problem of how to have multiple apps running in the same jetty instance, but each with their own props file that is editable without having to recompile the war.

So, the plan is:

1) pass the jetty resources dir as a system parameter when you start jetty: java -Djetty.resource.dir=$JETTY_HOME/resources -jar start.jar 
2) within the jetty resource dir, create a sub directory for each app running in jetty (make the name of the the dir the same as the context root)
3) put a props file in this sub directory following the same naming options as the usual Props file, (modename.username.hostname.props, etc)
3) put this code into your boot.scala:

val contextPath = LiftRules.context match {
  case c: HTTPServletContext => Full(c.path)
  case _ => Empty
}
info("Context Path is: " + contextPath )

val jettyResourceDir = Box.!!(System.getProperty("jetty.resource.dir"))
info("got jetty.resource.dir from system properties: " + jettyResourceDir)
val whereToLook = jettyResourceDir.flatMap( dir => {
  contextPath.map( cp =>
  for (
        propsname <- Props.toTry;
        fullname = dir + cp + propsname() + "props";
        file = new File(fullname);
        if (file.exists)
      ) yield fullname -> { () => Full(new FileInputStream(file))}
    )
})
      
whereToLook.foreach( w =>
  Props.whereToLook = () => w )


Seems to work, although I can't help thinking there must be a more elegant solution.

Is this one for the Cookbook, possibly?

Richard Dallaway

unread,
Jul 23, 2012, 11:51:25 AM7/23/12
to lif...@googlegroups.com

Is this one for the Cookbook, possibly?

Sure thing - the cookbook welcomes all contributions that answer questions. Feel free to add it to the deployment section maybe.  Or the wiki.

(Yes, I'm very far behind on email right now).

Cheers
Richard
Message has been deleted

Richard Dallaway

unread,
Nov 16, 2012, 7:56:38 AM11/16/12
to lif...@googlegroups.com
No, it didn't get added.  Feel free to.

On 15 November 2012 21:07, Jonathan Ferguson <jo...@spiralarm.com> wrote:
Did this ever get cook booked?
--

Damian Helme

unread,
Nov 16, 2012, 8:52:33 AM11/16/12
to lif...@googlegroups.com
Not yet - it's on my list of things to do. I wont be offended if you want to jump in a do it ;-)
Reply all
Reply to author
Forward
0 new messages