Get war name from within Config.groovy?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Get war name from within Config.groovy?

Ken Roberts
Hi,

I'm trying to implement externalized configuration of the app, but with a twist.

So starting from what's in the manual:
if(ServletContextHolder.servletContext) {
        def myName = ServletContextHolder.servletContext.servletContextName
        grails.config.locations = [ "classpath:${myName}.properties",
                            "classpath:${myName}.groovy"];
} else {
        System.out.println("servletContext is null!")
}


I want the config file to be <warName>.properties, where warName is whatever the deployer might have renamed the file to.  This will allow more than one instance of the war deployed at once, for different tasks.

The ServletConfig is null at this point, it takes the else block rather than the config.

Does anyone know how to get the name of the war file at this point in initialization?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Get war name from within Config.groovy?

rmachado
Hi,

Did you ever found a solution for this?

I need to do the same thing, but have no clues on how to do it.

Thanks!

Rodrigo
dlm
Reply | Threaded
Open this post in threaded view
|

Re: Get war name from within Config.groovy?

dlm
In reply to this post by Ken Roberts
Diito. I would love to know how to do this too!
Reply | Threaded
Open this post in threaded view
|

Re: Get war name from within Config.groovy?

Octavian Covalschi
Perhaps a better approach is to use some system property for each war deployed...

On Tue, Oct 23, 2012 at 10:03 AM, dlm <[hidden email]> wrote:
Diito. I would love to know how to do this too!



--
View this message in context: http://grails.1312388.n4.nabble.com/Get-war-name-from-within-Config-groovy-tp1316388p4636874.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



dlm
Reply | Threaded
Open this post in threaded view
|

Re: Get war name from within Config.groovy?

dlm
The issue is that I need to deploy two versions of the war to the same server, but I need to have each war look for it's own config file. For example myApp_TEST.war needs to look for and use myApp_TEST_config.groovy while myApp_MODL.war is on the same server using myApp_MODL_config.groovy. Currently I'm manually modifying the internal Config.groovy class to tell it which external groovy config to use and generating the war specifically for each region. Ideally I'd like to have one war that can be moved up and used in any region and have all of that region's specific setting in its groovy config file.

Normally we have separate servers for each region, however this app is more of a light usage util that run in a separate area with only test and prod servers, so test has to serve a dual purpose here.

Thanks,
D.L.
Reply | Threaded
Open this post in threaded view
|

Re: Get war name from within Config.groovy?

Octavian Covalschi
Yes, I've got what you're trying to do, but I don't think it's possible, though I'm not an expert...

So, instead I meant to suggest to use something else... somethig like this (if you're using tomcat):

//Config.groovy
if (System.properties["CONFIG_FILE"]) {
   grails.config.locations << "file:" + System.properties["CONFIG_FILE"]
}


// server.xml
<Context path="/testwar" docBase="testwar">
<Environment name="CONF_FILE" value="/path/to/test_config.groovy" type="java.lang.String" />
</Context>

<Context path="/uatwar" docBase="uatwar">
<Environment name="CONF_FILE" value="/path/to/uat_config.groovy" type="java.lang.String" />
</Context>

I know I did this using a jvm parameter and it worked, but I haven't tried through context/environment setting...

On Tue, Oct 23, 2012 at 10:28 AM, dlm <[hidden email]> wrote:
The issue is that I need to deploy two versions of the war to the same
server, but I need to have each war look for it's own config file. For
example myApp_TEST.war needs to look for and use myApp_TEST_config.groovy
while myApp_MODL.war is on the same server using myApp_MODL_config.groovy.
Currently I'm manually modifying the internal Config.groovy class to tell it
which external groovy config to use and generating the war specifically for
each region. Ideally I'd like to have one war that can be moved up and used
in any region and have all of that region's specific setting in its groovy
config file.

Normally we have separate servers for each region, however this app is more
of a light usage util that run in a separate area with only test and prod
servers, so test has to serve a dual purpose here.

Thanks,
D.L.



--
View this message in context: http://grails.1312388.n4.nabble.com/Get-war-name-from-within-Config-groovy-tp1316388p4636876.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



dlm
Reply | Threaded
Open this post in threaded view
|

Re: Get war name from within Config.groovy?

dlm
Ah, I see what you're saying now and I think that should work! Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Get war name from within Config.groovy?

a.shneyderman
In reply to this post by dlm
this works in Config files:

grails.config.locations << "file:${userHome}/.appdata/${appName}-config.groovy"

the appName I believe (I did not check this so some verification is
needed here)
comes from application.properties file. So if you can can change that
value during
the build - that should be possible with a script - you can feed to
each his own :-)

Cheers,
Alex.

On Tue, Oct 23, 2012 at 5:28 PM, dlm <[hidden email]> wrote:

> The issue is that I need to deploy two versions of the war to the same
> server, but I need to have each war look for it's own config file. For
> example myApp_TEST.war needs to look for and use myApp_TEST_config.groovy
> while myApp_MODL.war is on the same server using myApp_MODL_config.groovy.
> Currently I'm manually modifying the internal Config.groovy class to tell it
> which external groovy config to use and generating the war specifically for
> each region. Ideally I'd like to have one war that can be moved up and used
> in any region and have all of that region's specific setting in its groovy
> config file.
>
> Normally we have separate servers for each region, however this app is more
> of a light usage util that run in a separate area with only test and prod
> servers, so test has to serve a dual purpose here.
>
> Thanks,
> D.L.
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Get-war-name-from-within-Config-groovy-tp1316388p4636876.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email