External files with war files

Hi All,

I am moving a ROR web application to JRuby. So far it has been a very
pleasant and impressive experience. I am including all the gems I need
and creating an executable war file for distribution.

My question is, is there a way to use the executable war file yet still
have an external database.yml file, as well as, other files? The reason
I ask is the ROR web application is distributed to various platforms and
configurations where the database credentials may vary. How can I
support this ability where the war contains the database.yml and is used
when the war is started.

Any information is appreciated.

Thanks,
Rick

Hi Rick,

On Oct 23, 2011, at 8:06 PM, Rick F. wrote:

support this ability where the war contains the database.yml and is used
when the war is started.

Any information is appreciated.

There may be a solution that’s particular to the tool you’re using to
package the WAR, but I’ll put a plug in for my utility bcdatabase:

It’s purpose is to separate database credentials out to a server-level
configuration file. It works on both MRI and JRuby.

Rhett

Thanks Rhett. You solution Looks interesting. From what I can tell is
this a Linux solution only? The web application I distribute runs on
many different OSs including Windows.

Thanks,
Rick

On Oct 23, 2011, at 9:06 PM, Rick F. wrote:

support this ability where the war contains the database.yml and is used
when the war is started.

You can push configuration to the deployment(i.e. configured once per
Servlet container) by reading resources from the CLASSPATH. You can plug
stuff into your database.yml with erb. In Tomcat, I drop deployment
specific configuration files in $CATALINA_HOME/lib

  1. You use something like this in your database.yml to externalize the
    entire thing.

<% stream =
Java::Java.lang.Thread.currentThread.contextClassLoader.getResourceAsStream(‘database-yourapp.yml’)
%>
<%= stream.to_io.read %>
<% stream.close %>

  1. You can do something like the following to replace individual
    properties in database.yml with values read from a Java properties file.
    (JavaProperties is my own helper class)

<%
require ‘java_properties’
connection_properties = JavaProperties.new(‘myapp.properties’)
%>
production:
adapter: jdbc
username:
password: <%= connection_properties[‘myapp.password’] %>
driver: oracle.jdbc.OracleDriver
url: <%= connection_properties[‘jdbc.url’] %>

-lenny

Hi Rick,

On Oct 24, 2011, at 7:44 AM, Rick F. wrote:

Thanks Rhett. You solution Looks interesting. From what I can tell is
this a Linux solution only? The web application I distribute runs on
many different OSs including Windows.

The default path in which it looks for the database credential files
(/etc/nubic/db) is unixy, but it can be changed (either through an
environment variable or by passing a parameter to Bcdatabase.load in
your database.yml). The library itself is pure ruby and should work
anywhere ruby works. If you find something that doesn’t work on windows,
please don’t hesitate to file an issue1.

Rhett