Grails external configuraiton issue - grails

Externalizing Grails Datasource configuration
i have followed the steps in answered section of above question.
grails.config.locations = [ "classpath:appconfig.properties"]
and placed appconfig.properties in conf folder. But this configuration is loading. what is the most trusted way to load external database configruation in grails ? My grails version is 1.3.7.
EDIT:
Just now i have changed this code to
grails.config.locations = ["file:${userHome}/.grails/appconfig.groovy"]
and placed the config file in .grails folder in my home folder. it is working in GGTS and war file also.

Your config is not loaded when running with grails run-app? Or in deployment on tomcat? Or either?
Try to look at this answer

Related

Automating the use of external config files in Grails

I am doing what appears to be the best practices for using an external config file in Grails.
grails.config.locations = ["classpath:${appName}-config.groovy",
"file:./${appName}-config.groovy"]
if (System.properties["${appName}.config.location"]) {
grails.config.locations << "file:" + System.properties["${appName}.config.location"]
}
I put the config file in the root folder during testing and it works. And I manually put the config file in our Tomcat server's lib folder (in the classpath) during production and it worked. But I don't want to have to copy/create our external config file every time. After building a war and deploying an app, is it possible for my config file to be moved to the correct location so that I don't have to manually move it during deployment of any of my apps? Thanks.
Note: I would edit the title of the question to reflect your actual problem which is about automation.
It depends on how manual your existing process is...
Let's imagine the following:
You have a continuous integration engine such as Jenkins/Hudson running
You scp/rsync the external configuration file upon successful builds
You deploy the application to the server upon successful builds (assuming a gant deploy script under projectName/scripts -> Tomcat, JBoss, Websphere, etc.)
In out project we need to provide different configuration settings per environment (local, development, testing, production). While we want to avoid the hassle of updating config files on the different servers themselves, we do need to allow quick overriding of config values on a specific environment.
To accomodate these requirements we have the following setup of 'cascading' configuration files:
common.properties bundled in the .war file and is always loaded
xxx.properties files are bundled in the .war file, and depending on the value of an environment variable (appEnv) one or none of these configuration files is loaded (e.g. if the environment variable is yyy, yyy.properties is loaded)
configuration files on the local file system are found using the appEnv and appLibRoot environment variables. If a configuration file corresponding to appEnv.properties is found, it is loaded last.
Loading the config files on startp of the Grail application is done by simply providing a list of configuration file locations in Config.groovy. The AppEnv class creates the list of configuration files using the appEnv and appLibRoot environment variables, and checking which files actually exist in the classpath and on the file system.
Config.groovy
grails.config.locations = AppEnv.instance.configLocations

Running jRuby + Rails inside of Tomcat

I am currently using a platform where multiple web applications must interact with each other in a frameset. This set of web applications and the frameset is hosted on Tomcat.
Now the application we're working on is developed with jRuby and Rails. Is there anyway I can run my development environment inside of Tomcat similar to just running the jRuby -S Rails Server command so I can effectively debug?
The only way I've found is to generate a war using warble and then modifying the exploded war which seems really hacky. Any thoughts?
EDIT: I think my best bet is to generate a war, gut it, use symbolic links and figure out what gems / libs I need to copy from the war generation process. It's the best way I can think of.
one option to explore: deploy a little servlet to Tomcat which returns
HTTP/1.1 301 Moved Permanently
Location: http://localhost:3000
So far the best solution I have found is to setup a reverse proxy with Tomcat and point it to the Rails development server. This allows it to run, as expected on the client side, while still giving me debug control.
When I get a chance to do some more testing I'll edit my answer to include additional information.
go to the webapps folder in tomcat where you have deployed the war file, then find the web.xml file inside the expanded war file
The path to this file is generally /var/lib/tomcat7/webapps/your-project-here/WEB-INF/web.xml and inside this file you should find the
Changing this is one way to go about.
<context-param>
<param-name>rails.env</param-name>
<param-value>production</param-value>
</context-param>

Why are grails plugin assets not copied in the right place when packaging as a war?

I am using the Calendar Plaugin in my application and on local testing it works great. It loads its assets from
http://localhost:8080/YYYYYY/plugins/calendar-1.2.1/js/calendar.js
However, when deployed as a war the gsp file looks for the assets at
http://XXXX/YYYYYY/js/calendar.js (i.e. no /plugins/calendar-1.2.1/)
and fails. My question is why is the packaged file looking for the plugin assets in the root when deployed as a war when they are packaged into the plugins/calendar-1.2.1/ sub directory? If they are looked up in the root should some code be copying them that is not configured or working properly?
Resources plugin
Basically if you have the resources plugin installed and are using any of the <r:require and <r:layoutResources tags in your layouts and views you are using the framework.
The plugin handles resources such as css, javascript, images and their dependencies and I believe the plugin is installed by default in 2.0.1 so it might be worth looking into it as the missing link in your problem.

How do I get Weceem Grails plugin to save its content across application restart?

I have Weceem 1.0 plugin installed in an empty Grails 1.3.7 application. I did the initial setup from the docs page, and I switched the devDB from "mem" to "file" storage.
I can create a space, populate some content, but then when I restart the application (grails run-app), my space and content is gone.
The devDB.script and other files show traces of Weceem data, but I lose the content in the newly started application.
What do I need to do to get it persistent?
You need to remove the settings dbCreate = "create/create-drop" and replace it by "update" or "none" in your DataSource.groovy file for development environment.
you can also start running a mongo database,
$ grails install-plugin mongodb
remove hibernate and add this to your domain class, to save your stuff to mongodb:
static mapWith="mongo"

Deploying a .war made by Warbler to Tomcat

I was trying to simply make a .war file and put it into Tomcat's webapps directory. Simple, right? :)
What is puzzling me is that the directory structure of a JRuby app has the index.html file somewhere far in the application structure and Tomcat just can not find it by default.
Here is what I get when I point my url to the Tomcat install of the application:
http://128.48.204.195:8080/blog/index.html
How should I structure the build/deploy of a JRuby application so that it works on Tomcat when unwrapped out of a .war file?
first try http://128.48.204.195/blog
that will serve the root route (if defined in config/routes.rb) or a error saying nor route.
If you see this: http://krokinet.files.wordpress.com/2010/11/rails-welcome1.png
there is a default index.html file in /public/index.html
that file is generated with the app and you should remove it once your done an initial 'smoke test' (running your newly generated app the first time).
More information on the root route here: http://edgeguides.rubyonrails.org/routing.html#using-root

Resources