Java module : configuring external data sources in labkey.xml

LabKey Support Forum (Inactive)
Java module : configuring external data sources in labkey.xml bront  2015-03-09 14:31
Status: Closed
 
hi,

How can I configure an external data source during development such that building either writes the correct configuration data to labkey.xml (or at least doesn't over-write it)?

Thanks,

bront
 
 
Jon (LabKey DevOps) responded:  2015-03-09 14:49
Hi Bront,

So what you will want to do is to add an additional entry to your labkey.xml file that resides under the LABKEY_ROOT/webapps/ directory in your dev instance. This specific XML file acts as the template and creates a labkey.xml file that gets copied to the TOMCAT folder under TOMCAT_HOME/conf/Catalina/localhost/.

By default, the first few lines of that labkey.xml file will look like this:

===============
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="@@appDocBase@@" debug="0" reloadable="true" crossContext="true">
    
    <Resource name="jdbc/labkeyDataSource" auth="Container"
        type="javax.sql.DataSource"
        username="@@jdbcUser@@"
        password="@@jdbcPassword@@"
        driverClassName="@@jdbcDriverClassName@@"
        url="@@jdbcURL@@"
        maxActive="20"
        maxIdle="10"
        accessToUnderlyingConnectionAllowed="true"
        validationQuery="SELECT 1"
        />

    <Resource name="mail/Session" auth="Container"
        type="javax.mail.Session"
        mail.smtp.host="@@smtpHost@@"
        mail.smtp.user="@@smtpUser@@"
        mail.smtp.port="@@smtpPort@@"/>
===============

The data in the @@ sections retrieve their information from the LABKEY_ROOT/server/config.properties file. So you will want to add another entry to the XML file like this (my example uses a PostgreSQL Data Source):

===============
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="@@appDocBase@@" debug="0" reloadable="true" crossContext="true">
    
    <Resource name="jdbc/labkeyDataSource" auth="Container"
        type="javax.sql.DataSource"
        username="@@jdbcUser@@"
        password="@@jdbcPassword@@"
        driverClassName="@@jdbcDriverClassName@@"
        url="@@jdbcURL@@"
        maxActive="20"
        maxIdle="10"
        accessToUnderlyingConnectionAllowed="true"
        validationQuery="SELECT 1"
        />

<Resource name="jdbc/pgDataSource" auth="Container"
       type="javax.sql.DataSource"
       username="USERNAME"
       password="PASSWORD"
       driverClassName="org.postgresql.Driver"
       url="jdbc:postgresql://localhost:5432/test"
       maxActive="20"
       maxIdle="10" accessToUnderlyingConnectionAllowed="true"/>

    <Resource name="mail/Session" auth="Container"
        type="javax.mail.Session"
        mail.smtp.host="@@smtpHost@@"
        mail.smtp.user="@@smtpUser@@"
        mail.smtp.port="@@smtpPort@@"/>
===============

This will create a permanent data source to your labkey.xml file during development and will not get overwritten when you do any build updates.
 
For more information on configuring a specific external data source, please visit the link below:

https://www.labkey.org/wiki/home/Documentation/page.view?name=externalSchemas#config

Regards,

Jon
 
bront responded:  2015-03-10 06:54
Jon,

Great. Just what I was looking for.

Many thanks,

bront