Grails
  1. Grails
  2. GRAILS-2534

Allow configuration of context path

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.3
    • Component/s: Configuration
    • Labels:
      None
    • Patch Submitted:
      Yes

      Description

      It can be useful to be able to define the context path that jetty will use for the application - for example, if you are running apache in front of jetty for development.

      The context path could be specified in the following locations:
      1. System property
      2. application.properties
      3. Config.groovy

      If not specified in one of these, then it should default to what it does now, 'grailsAppName'.

      Some sample code:

      In RunApp.groovy:

      Change the runApp target to derive the context path:

      // Get the application context path by looking for a property named 'app.context' in the following order of precedence:
      // System properties
      // application.properties
      // config
      // default to grailsAppName if not specified

      props = Ant.antProject.properties

      appContext = System.getProperty("app.context")
      appContext = appContext ? appContext : props.'app.context'
      appContext = appContext ? appContext : config.app.context
      appContext = appContext ? appContext : grailsAppName

      if(!appContext.startsWith('/')) {
      appContext = "/$

      {appContext}"
      }

      and modify the StatusFinal event to reflect the appContext:

      event('StatusFinal', ["Server running. Browse to http://localhost:$serverPort$appContext"])

      In the setupWebContext target, use the appContext variable in the webContext definition:

      webContext = new WebAppContext("${basedir}/web-app", "${appContext}

      ")

      Now, you can affect the context path in 1 of 3 ways:

      1. grails -Dapp.context=mycontext run-app
      2. in application.properties, define property:
      app.context=mycontext
      3. in Config.groovy define the app.context property:
      environments {
      development

      { app.context='mycontext' }

      }

      I've attached a modified version of the grails-1.0 RunApp.groovy file for comparison.

      For more information, see
      http://www.javathinking.com/?p=49
      http://www.nabble.com/Defining-the-context-path-in-application.properties-td12976557.html

      Thanks.

        Issue Links

          Activity

          Hide
          Paul Rule added a comment -

          I have produced a better implementation:

          • appContext is now defined in Init.groovy so it is available to all scripts
          • RunApp.groovy and RunWar.groovy use the appContext to configure the server and display the url.
          • RunAppHttps.groovy reuses RunApp.groovy so the only change here is for displaying the url.
          Show
          Paul Rule added a comment - I have produced a better implementation: appContext is now defined in Init.groovy so it is available to all scripts RunApp.groovy and RunWar.groovy use the appContext to configure the server and display the url. RunAppHttps.groovy reuses RunApp.groovy so the only change here is for displaying the url.
          Hide
          Burt Beckwith added a comment -
          Show
          Burt Beckwith added a comment - http://jira.codehaus.org/browse/GRAILS-2435 is similar to this one
          Hide
          Graeme Rocher added a comment -

          Thanks for the patch! I made one change in that the Config.groovy variable is called grails.app.context. So to run an application in the root context you do:

          grails.app.context = "/"

          In Config.groovy

          Show
          Graeme Rocher added a comment - Thanks for the patch! I made one change in that the Config.groovy variable is called grails.app.context. So to run an application in the root context you do: grails.app.context = "/" In Config.groovy

            People

            • Assignee:
              Graeme Rocher
              Reporter:
              Paul Rule
            • Votes:
              5 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development