2

I'm on Windows 7. Inside my Grails (2.3.6) app's Config.groovy file I have:

grails.config.locations = [
    "file:/etc/myapp/env.groovy"
]

// fizz.buzz is defined inside env.groovy
println "fizz.buzz=${fizz.buzz}"

At the root of my D:\ drive:

etc/
    myapp/
        env.groovy

When I run grails -Dgrails.env=local run-app I get the following output:

fizz.buzz=[:]

What's going on here? Why can't Grails find my env.groovy file and/or read its properties?

My permissions:

enter image description here

Running File('/etc/myapp/env.groovy').absolutePath in the Groovy Console, I get:

Exception thrown

groovy.lang.MissingMethodException: No signature of method: ConsoleScript2.File() is
applicable for argument types: (java.lang.String) values: [/etc/myapp/env.groovy]
Possible solutions: find(), find(groovy.lang.Closure), use([Ljava.lang.Object;),
with(groovy.lang.Closure), is(java.lang.Object), wait()

I also tried running my app and passing in the value for fizz.buzz on the command line via a switch like so:

grails -Dgrails.env=local -Dfizz.buzz="true" run-app

The result was the same. Is it possible that the configs ARE being read in, but are just not available (caching, etc.) at the time that the println is running inside Config.groovy?

saw303
  • 8,051
  • 7
  • 50
  • 90
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
  • 1
    where did you put this line: `// fizz.buzz is defined inside env.groovy println "fizz.buzz=${fizz.buzz}"` If this is INSIDE of `Config.groov`y, you won't get output, try printing it from controller e.g `render grailsApplication.config.fizz.buzz` Also make sure that user that is running grails has read permissions on `/etc/myapp/env.groovy` – toske Jul 30 '14 at 11:43
  • Thanks @toske (+1) - however you are incorrect, `Config.groovy` is just like any other Groovy file and `println` statements **do** work from inside of it. The `println` you are referring to *is in fact* located inside my `Config.groovy` (try it out for yourself!). Also please see my updated question that contains my security permissions for the folder. – IAmYourFaja Jul 30 '14 at 11:47
  • 1
    No you dont need to use backslashes. It should work. If you open a `groovyConsole` and execute `new File('/etc/myapp/env.groovy').absolutePath`, what did you get? – matcauthon Jul 30 '14 at 11:48
  • Thanks @matcauthon (+1) - I think we're starting to get somewhere. Please see my update which includes the output from the Groovy Console. – IAmYourFaja Jul 30 '14 at 11:52
  • 1
    Give double slash and see if it works. Also test it with complete path: "C:\\\\env.groovy" – Lalit Agarwal Jul 30 '14 at 11:57
  • 1
    It should be `new File('/etc/myapp/env.groovy').absolutePath `...including the `new` keyword – matcauthon Jul 30 '14 at 12:01
  • Thanks again @matcauthon (+1) - the output is `Result: D:\etc\myapp\env.groovy`. – IAmYourFaja Jul 30 '14 at 12:05
  • Thanks @LalitAgarwal (+1) - but the output from the Groovy Console indicates Groovy has no problem finding my file, thoughts? – IAmYourFaja Jul 30 '14 at 12:06
  • 1
    Can you try including like this: grails.config.locations = [ "file:D:\\etc\\myapp\\env.groovy" ] – Lalit Agarwal Jul 30 '14 at 12:12
  • Thanks @LalitAgarwal (+1) - but that doesn't work either... – IAmYourFaja Jul 30 '14 at 12:15
  • All - please see my update which shows `Config.groovy` failing to read my `fizz.buzz` property **off of the command line**. Might be chasing a red herring here with file system structure/permissions/etc. – IAmYourFaja Jul 30 '14 at 12:19

0 Answers0