Grails 2.4 won't read config file from /opt - grails

Please note: Although I'm using the Grails Shiro plugin I believe this to be a core Grails problem, having nothing to do with the plugin whatsoever.
Mac (Yosemtie) and Grails 2.4.5 here. Here's the top 2 lines from my Config.groovy:
String configFileAbsPath = System.getProperty('configFileAbsPath')
grails.config.locations = [ "file:${configFileAbsPath}" ]
So to run locally I do something like:
grails -DconfigFileAbsPath=/Users/myuser/tmp/myapp.properties run-app
When I run this exact invocation, my app starts up and behaves just fine.
However, in non-local environments I want my config file to live under /opt/myapp/myapp.properties. So on my local machine I create a /opt/myapp directory, and then ran chmod -R 777 /opt/myapp. I then copy myapp.properties to it and run:
grails -DconfigFileAbsPath=/opt/myapp/myapp.properties run-app
This produces the following stack trace:
| Error Error generating web.xml file (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
groovy.lang.MissingPropertyException: No such property: shiro for class: java.lang.String
at ShiroGrailsPlugin$_closure4_closure30_closure34.doCall(ShiroGrailsPlugin.groovy:248)
at ShiroGrailsPlugin$_closure4_closure30_closure34.doCall(ShiroGrailsPlugin.groovy)
at ShiroGrailsPlugin$_closure4_closure30.doCall(ShiroGrailsPlugin.groovy:243)
at ShiroGrailsPlugin$_closure4_closure30.doCall(ShiroGrailsPlugin.groovy)
at ShiroGrailsPlugin$_closure4.doCall(ShiroGrailsPlugin.groovy:242)
I seriously doubt that the location of an external config file, or the file permissions set on the config file (or its parent dir) would break the Grails Shiro plugin. I think this is just a misleading Grails/Groovy exception. Most likely some kind of security exception is causing something to not load/populate correctly (and fail silently), and then when Grails Shiro kicks in during run-app, its missing something that should be there and is causing run-app to die.
Any ideas as to what is going on, or what the fix is?
Update: Running grails clean, grails clean-all and/or grails refresh-dependencies prior to invoking grails run-app do not help/solve this error either.

I generally prefer to have .groovy file for external config rather than .properties because I can write printlns into it to check whether the file is loaded or not.

Related

classpath property file in grails app is not being used

My problem is that I've put a well-formed properties file in my classpath and told grails to look for the properties file in my classpath, but the properties in the file aren't overriding the existing ones.
In my config.groovy I have the lines:
grails.config.locations = [ "classpath:${appName}-config.properties",
"file:./${appName}-config.properties"]
// verified that appName is being used. It prints out classpath:XXX-config.properties, as expected, where XXX is my appname.
println "grails.config.locations: ${grails.config.locations}"
In my XXX-config.properties, I specify a different DB connection URL (this is the one I want to use):
dataSource.url=jdbc:postgresql://products.yyyyy.ap-southeast-1.rds.amazonaws.com:5432/mydatabasename
Then I put the XXX-config.properties in my classpath and startup tomcat7, but the errors are thrown, saying it can't find my deliberately fake db, meaning the database property did not get overridden.
Now I'm thinking my classpath is wrong, but I do ps aux | grep tomcat which tells me that the command line arg for tomcat7 contains " -classpath :/home/jbu/:_other_paths_here_". Note I put my properties file at /home/jbu/XXX-config.properties. I am slightly concerned about that leading colon, but it doesn't seem to cause any other problems.
So the classpath dir appears correct, so now I thought maybe my properties file isn't properly formatted, so I added a harded "file:/home/jbu/XXX-config.properties" to my grails.config.locations, and the properties were found and successfully overridden, meaning nothing is wrong with the properties file itself.
I don't have any more ideas here. Can someone help me out?
Sidenote: I modified the CLASSPATH variable for tomcat7 by adding this line to /usr/share/tomcat7/bin/setenv.sh:
export CLASSPATH="${CLASSPATH}:/home/jbu/"
This (among with many other things in Grails, it seems) is broken. Sigh...I'm using grails 2.4.5 so I'm a bit surprised that it has been broken since 1.3.5.
http://jay-chandran.blogspot.com/2010/10/grails-using-external-properties-file.html
Grails 1.3.5: How to configure Datasource.groovy to either connect to MySQL or SQL Server

"Error occurred running Grails CLI: null" when running grails 3.0 command line

I'm trying to run grails list-profiles, but receive the following error:
snowch#snowch-ws2:~/repos$ grails list-profiles --stacktrace
| Error Error occurred running Grails CLI: null (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.NullPointerException
at org.grails.cli.profile.git.GitProfileRepository.getAllProfiles(GitProfileRepository.groovy:72)
at org.grails.cli.profile.commands.ListProfilesCommand.handle(ListProfilesCommand.groovy:43)
at org.grails.cli.GrailsCli.execute(GrailsCli.groovy:173)
at org.grails.cli.GrailsCli.main(GrailsCli.groovy:99)
| Error Error occurred running Grails CLI: null
My versions are:
snowch#snowch-ws2:~/repos$ grails --version
| Grails Version: 3.0.1
| Groovy Version: 2.4.3
| JVM Version: 1.7.0_75
This was on a fresh install of grails and gvm.
The command grails create-app myapp works without error.
This question is similar to Grails 3.0 error, nullpointer, however, that question does not state what command is being run.
After searching online, I found that I needed to set my GRAILS_OPTS environment variable as follows before running the command:
export GRAILS_OPTS="-XX:-UseSplitVerifier -Xverify:none"
Source of fix: https://grails.org/news/1292028
I have not figured out, what is the exact cause of the error, but it seems to occur if you try to run grails 3 in the system where grails 2 is also installed.
What I did to get the command run - I created the project in a new directory. The directory for my old grails app was:
/home/me/projects/oldgrailsapp
when I tried to execute the grails command in /home/me/projects it failed, but when I tried this in another directory /home/me/projects_new, it succeeded. So I guess that the problem was that old grails configuration was somehow interfering with the new one.
I also removed references to old grails and groovy versions from the PATH variable by editing .bashrc file in my home directory (I really do not know if it was needed).
I had same experience when I was working on "Building an Andoird Client" guide, I got the following message whenever I try to create an app in the same folder where I've created the first app grails-app :
| Error Error occurred running Grails CLI: null (Use --stacktrace to see the ful
l trace)
So obviously, when you create a grails app in folder containing "grails-app" directory, grails will consider this folder as full grails application, hence cannot create-app in that directory.
I used:
Grails 3.1.15
Java 1.8.0.101
Hope this help.
It worked for me now.
this was my setting
GRAILS_HOME=C:\Users\murali.solayappan\apps\grails-3.1.11
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_102
I received the same error while launching "grails" for the first time
**Error occurred running Grails CLI: connect timed out**
After reading GRAILS_HOME\bin\grails.bat i found that executing "grails" while in GRAILS_HOME dir makes some difference. So I did the same
Now i received error stating that GRAILS couldn't find a particular maven package from my mirror repository - printed my private nexus repository url. I know that's my private repo and not connected to internet.
so I changed the MY_HOME_DIR.m2\"settings.xml" with the one came by default in Maven.
After that executed "grails" while in %GRAILS_HOME% dir.
It worked like breeze !!! I got grails prompt.
C:\Users\murali.solayappan\apps>grails
| Enter a command name to run. Use TAB for completion:
grails> exit
Somethimes it happens when you have wrong version of grails installed for the project you want to run it on
try to run it somewhere else and see if you get the same error
i had the same issue because i was using Grails 1.3.5 witj Java 8 which are incompatibles. I changed with Java 7 and it works fine.

Grails 2.1.1 - Logback integration

I'm developing with Grails 2.1.1 and now I want to integrate Logback (http://logback.qos.ch) as the default logging framework as it should provide some better logging features and could be also configured via Groovy.
As Logback 1.0.7 (latest) does only work with slf4j 1.6.6 I want to upgrade the Grails dependeny. Grails 2.1.1 is using slf4j 1.6.2. How to do this properly?
I tried the following: in BuildConfig.groovy I exclude grails-plugin-log4j and slf4j-api
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
excludes "grails-plugin-log4j", "slf4j-api"
}
...
}
and I try to load slf4j-api 1.6.6 in compile build and runtime along with the other necessary libraries
grails.project.dependency.resolution = {
...
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
compile "org.slf4j:slf4j-api:1.6.6"
build "org.slf4j:slf4j-api:1.6.6",
"ch.qos.logback:logback-core:1.0.7",
"ch.qos.logback:logback-classic:1.0.7"
runtime "org.slf4j:slf4j-api:1.6.6",
"org.slf4j:log4j-over-slf4j:1.6.6", // logback dependency for classic module, as seen on http://logback.qos.ch/dependencies.html
"ch.qos.logback:logback-core:1.0.7",
"ch.qos.logback:logback-classic:1.0.7"
}
...
}
now, if I want to do anything from the Grails commandline, either grails compile or grails clean, it's complaining that it couldn't execute the script because it couldn't find the LoggerFactory class:
| Loading Grails 2.1.1
| Configuring classpath
| Error Error executing script Compile: org/slf4j/LoggerFactory (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:272)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.<clinit>(PathMatchingResourcePatternResolver.java:169)
| Error Error executing script Compile: org/slf4j/LoggerFactory
How can I upgrade the underlying slf4j-api properly?
If I don't exclude the slf4j-api first, I get a conflict with the "old" 1.6.2 api marked as evicted when calling grails dependency-report...
Also, I'd love to have an external config file for Logback. How would I implement it? With Log4j I just declared a log4jConfigurer bean within the conf/spring/resources.groovy file - how would it be done with Logback?
Has anybody experience in logging Grails 2.1.1 with Logback and could give me any advice for this issue?
As I think that this question would be also a matter of fact for other developers willing to implement the Logback Logging Framework with Grails, I'll share my progress on the topic within this answer - trying not to overload the initial question with progress information.
I still had no luck in updating slf4j within Grails, so I stuck
with the solution to simply overload the slf4j-api dependency.
Grails would show no error on grails dependency-report, just an
"eviction notice" on the older slf4j dependency (1.6.2). This seems
to work but I'll keep on searching for a better solution on this
topic.
I'm now able to load an external config file for Logback through
a ServletContextListener and a ConfigLoader class
implemented in grails-app/src/java, with the
ServletContextListener registered within the web.xml file. (to
get the web.xml simply execute grails install-templates on the
commandline. You'll find it under
grails-app/src/templates/war/web.xml) Be sure to make it the first
<listener/> entry within your web.xml so that Logback gets
configured and loaded as soon as possible.
I found this solution along with the full code sample over at
https://bowerstudios.com/node/896 which was the best and shortest
example I found on this topic which seems to work!
This solution just loaded the external configuration file and used
it within the ConfigLoader class but didn't set it for the whole
Grails application. So I googled around a bit more and I found a
solution from Logback, available at GitHub (https://github.com/qos-ch/logback-extensions) and integrating with the
Spring Framework, so I took these classes from this page and
the LogbackConfigurer class from here and tweaked them to fit
my needs.
Now everything works like a charm and I'am able to create an external configuration file and - what I like best - it's hooking in
with the log object which is injected to e.g. Controller classes
by default.
Hope this is also a help for other developers too ;)
If you've got a better or more "groovy" solution for this, pleas let me know!

Issue Deploying a Grails 2.1.1 app to JBoss because of Xerces

I have a Grails app that uses the Rest plugin
When I drop my war into my JBoss deploy directory and start it up, the deployment of the app fails because of the following error:
2012-11-01 15:48:33,931 ERROR [org.jboss.web.tomcat.service.deployers.JBossContextConfig] XML error parsing: context.xml
org.jboss.xb.binding.JBossXBRuntimeException: Failed to create a new SAX parser
I believe this refers to the grails app containing a version on xercesImpl as well as JBoss having it's own. We usually rectify this by removing xercesImpl from our apps or setting them to "provided" scope.
I'm trying to figure out how I fix this deploy issue. I'm assuming I have to edit the BuildConfig.groovy script and tell it, somehow, to exclude xerces right? How would I do that for this plugin? If this were a "dependency" that appears to be easy to specify the exclusions. But I'm not sure how to do it for this plugin...
any ideas?
In your BuildConfig.groovy add this:
inherits('global') {
excludes 'serializer'
}
It turns out, doing the following in the plugin section of my BuildConfig.groovy did the trick after all...
compile(":rest:0.7"){
excludes "xercesImpl"
}

Grails JBOSSAS Plugin -- How To get it To Work?

Newbie Question:
I've been required to deploy a grails app to jboss 5. I'm having a hell of a time figuring out how to take advantage of the grails jbossas plugin. I've followed the documentation as best as I know how, but I get the same exceptions just as if the plugin was never there.
Here's the documentation i've been following:
http://grails-plugins.github.com/grails-jbossas/docs/manual/guide/2%20Usage.html
I've added the plugin to the BuildConfig.groovy plugin{} closure. I then called grails war. Nothing happens and my war deploy bombs out.
Could somebody give a newbie a little hand holding to get this plugin to work? Unfortunately, I'm finding the documentation to be wanting in the regard of actually telling you how to use it, or when the plugin will do its magic.
UPDATE:
My environment:
Mac OS X Lion Dev machine
Grails 2.0.3
JBoss 5.1.0 -- running a Liferay instance.
Burt, I've done the following:
grails generate-jboss-deploy 5
grails war.
scp the generated war file to the deploy-jboss directory on my remote server.
Dutifully, jboss picked up the new war and attempted to deploy it. I'm getting the following (now dreaded) exception:
Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator
Per the usage instructions, I've modified Datasource.groovy's hibernate configuration:
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
validator.apply_to_ddl = false
validator.autoregister_listeners = false
}
The only file that seems to have been modified or created by running the generate-jboss-delpoy 5 script is WEB-INF/jboss-web.xml. It's contents are:
<jboss-web>
<class-loading java2ClassLoadingCompliance="false">
<loader-repository>
sappi-label:loader=sappi-label.war
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
</loader-repository>
</class-loading>
</jboss-web>
I confirmed that the jboss-web.xml file is present in the generated war file (exploded, then checked the directory).
Burt: what files other than jboss-web.xml should have been altered?
UPDATE (Again):
I don't think there's anything wrong with the jbossas plugin. I've done more testing and see that the plugin is doing what it is supposed to do: remove jars, put in jboss-web.xml. I haven't been able to confirm that it modifies the hibernate config, but I assume it is. I think the problem lies within the server I'm attempting to deploy to, a Liferay instance.
regardless of what I'm doing I get an exception saying that slf4j was unable to load successfully. Nothing more, nothing less. I'll keep whacking away at the problem, but it is out of scope of my original question. Burt, thanks for your help. If you have any ideas about why slf4j vomits in a Liferay/jboss environment, please let me know.
Regards.
Thanks!
I guess I didn't make it clear that you need to run the generate-jboss-deploy script, passing in the major version of JBoss that you're using, so in your case generate-jboss-deploy 5. I've updated the docs to describe this.
If this doesn't help please update your question with some indication of what the errors that you're seeing are.

Resources