Posts

Showing posts with the label grails

Error executing script War: No such property: stagingDir for class:_Events

While trying out my new Morph Grails hosting account, I installed the morph-deploy plugin and then promptly discovered that 'grails war' failed with Error executing script War: No such property: stagingDir for class: _Events It turns out this is a known problem with Grails 1.1 and the solution is to delete the _Events.groovy file in [your home dir]/.grails/1.1/projects/[your application]/plugins/morph-deploy-0.1/scripts

Modifying web.xml in Grails

I'm trying out Grails application hosting at Mor.ph with a  free developer account . To put up a sample application, I wanted to be able to protect the site with basic authentication so that it won't be accidentally found and played with. So, following the Mor.ph instructions, I needed to modify web.xml to add security constraints and a login mechanism. As with most things Grails,  the solution  was easy - simply install the templates and modify the web.xml template. But, at the moment I have to uncomment it in order to get it running locally - what I really need is a way to only put this modification in when the environment is production...

Grails Openid plugin and Xerces

I just created a grails 1.1 application, and installed the openid plugin. When starting the application, I got the following exception: 2009-03-17 22:25:41,090 [main] ERROR context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'consumerManager': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.openid4java.consumer.ConsumerManager]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/xerces/parsers/DOMParser at java.security.AccessController.doPrivileged(Native Method) ... Caused by: java.lang.NoClassDefFoundError: org/apache/xerces/parsers/DOMParser at org.openid4java.discovery.Discovery. (Discovery.java:47) at org.openid4java.consumer.ConsumerManager. (ConsumerManager.java:51) ... 21 more I worked around this by dropping xercesImpl-2.6.2.jar in the l...

Groovy and Grails books

The catalog of Groovy and Grails books keeps growing, so if you are in the market for some, check out these sources: Pragmatic programmer Grails Groovy Apress Grails Groovy Manning Grails in Action Groovy in Action On Amazon:

Do you need a Grails developer in Sydney?

If you haven't heard of Grails, head on over to Grails.org and have a look. Grails breaks down the barriers to the Java platform and gives you a highly productive environment for building web applications - and you are always free to utilise plain Java seamlessly. Having used Grails on my personal projects , and written several Grails plugins, I'm sold. My time is precious and I can achieve a lot with a small amount of code, in a small amount of time - free of a lot of the bureaucracy of "Enterprise" Java applications. If you are interested in working with Grails and need a conscientious, motivated guy on your team, drop me a line: paulrule1@gmail.com . To get to know me better, see: http://www.myonlineprofile.net/profile/prule http://www.ohloh.net/stacks/27540 http://www.linkedin.com/in/paulrule

URI "file:./" is not hierarchical

Just recently I came across the following exception when deploying a simple Grails application to Tomcat : URI "file:./" is not hierarchical The application was so simple and ran locally on tomcat-6.0.16 - it had to be something environmental. Comparing the differences between machines showed that it was the JVM that was different. The JVM that produced the error was: java version "1.5.0" gij (GNU libgcj) version 4.2.4 (Ubuntu 4.2.4-1ubuntu3) while the Sun JRE 1.6 was okay: java version "1.6.0_03" Java(TM) SE Runtime Environment (build 1.6.0_03-b05) Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode) Note that this occurred on Ubuntu 8.04 64 bit Linux: Linux dev 2.6.24-21-generic #1 SMP Mon Aug 25 16:57:51 UTC 2008 x86_64 GNU/Linux

grails-selenium-0.5

I've just released a new version (0.5) of the selenium plugin , which fixes compatibility problems with Grails 1.0.3. Hopefully all is well now and I'd like to apologise to all the users out there who ran into problems. If you encounter any more issues, you can email me at paul@javathinking.com. On another note, it would be cool to know how much a plugin is being used. For example, I've got no way of knowing if anyones actually using any of the plugins I've written so its hard to prioritise work. Perhaps we need a download counter to give a rough indication... ?

grails-selenium-0.3

Version 0.3 of the grails selenium plugin is now available. This version: Adds GSP support for writing tests Fixes bug where hidden directories were shown as suites Fixes bug on windows with invalid URIs to html tests To use GSP to generate the tests, use the <sel:test> tag, followed by nested <sel:row> tags. <sel:row> can take either: one 'line' attribute where the command, target and value are pipe separated as per the pipe separated value files or separate 'command', 'target', and 'value' attributes. Because this is a normal GSP file, you have full access to the normal variables and you could call other classes for utility methods. An example GSP test: <g:set var="bookTitle" value="book0d"/> <sel:test name="MyTest"> <sel:row command="open" target="${request.contextPath}"/> <sel:row line="clickAndWait|link=BookController"/> <sel:row line=...

grails-jttaglib-0.1

grails-jttaglib plugin is a small collection of convenience tags. The sample code below assumes you have a domain class that looks like this: class Book { String title="my new book" String content static def constraints = { title(maxSize:20) content(maxSize:200) } } When using these tags, you must have the following in the page - normally in the head block: <g:javascript library="prototype"/> <jttext:script /> textArea Creates a TextArea HTML element, where the maximum number of characters is limited by the constraints on the domain object, and tabs can be allowed if desired. Sample use: <jttext:textArea object="${new Book()}" name="content" allowTabs="true"/> <jttext:statusDiv for="content" /> The number of remaining characters available are displayed in the status div. If allowTabs is set to true, tabs can be entered in the text area. textField Creates a text input type usi...

Regression testing grails plugins

For regression testing the grails plugins I've released, I have a shell script that: cleans up any previous runs packages the current code for the plugin OR downloads a release from my web site creates a new grails app copies preprepared resources into this new grails app installs the plugin Now all I have to do is run the application and test it through the browser (potential for selenium to help here?). This is great for testing the plugin against a new grails version, or just for testing code changes to the plugin itself. I put the script in <project_home>/test/regression/run.sh and the resources in <project_home>/test/regression/resources. The resources directory contains files like domain objects etc in the same directory layout as a normal grails project. This way I just need to copy the contents of the resources directory over the top of my newly created project. I should have written it as an ANT script though (what was I thinking?) - then it would be platf...

Allowing tabs in a text area

In addition to controlling the maximum number of characters in a text area , I also want to allow the user to enter tabs. But default, hitting tab would move out of the text area to the next control on the page. Overriding this behavior can be done by using the onKeyDown event controller so you can: check if the tab key has been pressed if it has, insert a tab at the current cursor location put focus back into the text area I've extended my little TextAreaTagLib to handle an 'allowTabs' attribute. Now you can allow tabs to be entered just by using allowTabs="true". I've also incorporated the work from the TextField modification so that the number of characters can be limited based on the maxSize constraint on the object. Sample use: <g:javascript library=”prototype”/> <jttext:script /> ... <jttext:textArea object="${new Book()}" name="content" allowTabs="true"/> <jttext:statusDiv for="content...

grails-selenium-0.2

I've just uploaded a new version of my Selenium plugin for Grails . You can download it from http://www.javathinking.com/grails/grails-selenium-plugin/0.2/grails-selenium-0.2.zip . The only significant enhancement is to support tests nested in directories. Now, the suite page displays a list of all of the directories in the tests location. The default (top level) suite shows all tests in all directories. You can click anywhere in this suite heirarchy to load only those tests in that directory. Let me know what you think of this implementation. There are probably several different ways to go about handling the directory structure, and this is just one implementation. I hope you find it useful! (for more complete information about this plugin, see grails-selenium-0.1 .

grails-selenium-0.1

This release has been superseded - Please see http://grails.codehaus.org/Selenium+plugin for the latest release information. I'm a big fan of Selenium - it lets me test my web applications easily, quickly, and inside the browser. Now I've created a Grails plugin to bring the efficiency of Selenium to Grails projects easily. When you install this plugin, it will download the Selenium-Core distribution (currently version 0.8.3 - 1.5MB) and extract it into your grails application (into <grails project>/web-app/selenium/core). Now you simply create your Selenium tests - putting them in <grails project>/web-app/selenium/tests. This plugin will automatically generate your test suite by listing all of the files in the selenium/tests directory. You can create tests as standard HTML as per the selenium documentation (and easily created using SeleniumIDE ). Or, you can for-go the HTML for pipe delimited text files (*.psv) - this plugin will convert the pipe delimited fil...

404 with Grails

Grails allows you to specify a custom 404 page simply using the UrlMappings.groovy class: class UrlMappings { static mappings = { "500"(controller:"errors", action:"serverError") "404"(controller:"errors", action:"notFound") } } This allows you to direct to a controller where you can then forward to a view: class ErrorsController { def serverError = { render(view:'/error') } def notFound = { render(view:'/notFound') } } I started off with a simple view using the 'main' layout: <html> <head> <meta name="layout" content="main" /> </head> <body> Page not found! </body> </html> But for some reason, the layout does not get applied. I haven't dug to the bottom of this yet, but I have found a work-around: <g:applyLayout name="main"> <body> Page not found! </body> </g:applyLayout> Now the layout is applied and th...

Developing with Grails and Apache2

In production I use Apache2 in front of Tomcat. The configuration for this is quite simple and standard. However, while developing Grails applications I wanted to run the same configuration, so that there are very few differences between my development and production environments. In Apache, I use named virtual hosts to forward to Tomcat, and Tomcat is configured with web applications corresponding to the virtual host name, with just '/' as the context path. Grails uses Jetty, and when running 'grails run-app' a Jetty container is configured and started. This is fine for me, I don't think I really need to switch to Tomcat in development, but running Apache2 in front of it would be very nice. This way I don't need to worry about differences in URLs. I'm not familiar with Jetty at all, so the simplest and fastest way to get this working was to make a copy of the RunApp.groovy script that comes with Grails and change it so that it looks for the context path def...

grails-p6spy-0.2

This information is out of date - please see http://grails.org/plugin/p6spy for the current documentation. Grails 0.6 was recently released, and this new version included changes to the way the DataSource is defined. So, to make my grails-p6spy-plugin compatible with 0.6, here is a new release: grails-p6spy-0.2.zip P6Spy lets you monitor the JDBC queries by proxying your database driver. In addition to logging the prepared statements, it also logs the sql with parameters in place so you can copy and paste the exact sql into your favourite database client to test the results. This Grails plugin makes it easy to utilize P6Spy in your Grails applications. Introduction This plugin contains 2 files - the p6spy jar and spy.properties. After installing the plugin in your Grails application, you can find them in: <project directory>/plugins/p6spy-0.2/grails-app/conf/spy.properties <project directory>/plugins/p6spy-0.2/lib/p6spy-1.3.jar The install script updates your DataSourc...

Changing code in Grails services

I've been using Grails for the last couple of months, and I'm loving it. While looking up some reference information, I stumbled across this gem . Its always been frustrating when updating services that the server needed to be restarted. Well, this problem has been caused because I've been specifying the type of my services instead of using the def keyword. Now that I'm not specifying the type, no more server restarts!

Grails P6Spy plugin

This information is out of date - please see http://grails.org/plugin/p6spy for the current documentation. I wanted to have a go at creating a Grails plugin so I thought I'd write one to make it easy to add P6Spy to your Grails application. The experience was very good. The structure and distribution mechanism is excellent and the Grails guys have done a great job. Here's the result: grails-p6spy-0.1.zip P6Spy lets you monitor the JDBC queries by proxying your database driver. In addition to logging the prepared statements, it also logs the sql with parameters in place so you can copy and paste the exact sql into your favourite database client to test the results. This Grails plugin makes it easy to utilize P6Spy in your Grails applications. Introduction This plugin contains 2 files - the p6spy jar and spy.properties. After installing the plugin in your Grails application, you can find them in: <project directory>/plugins/p6spy-0.1/grails-app/conf/spy.properties ...

Grails and Eclipse

I've just been lead astray by a little problem with my Eclipse setup, while working on a Grails project. It's documented that when working on a Grails project and using the Groovy Eclipse plugin , you must turn off 'Enable Groovy Compiler Generating Classes' otherwise it will interfere with your Grails project. While working on a Groovy project I had re-enabled this, and after switching back to my Grails project, I would get this exception when running grails run-app : Server failed to start: org.mortbay.util.MultiException [org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: Note.save() is applicable for argument types: () values: {}] (Note.groovy is my domain class) When I noticed a bunch of Eclipse generated content in the root of my project I quickly remembered this issue. Since the setting in question is a workspace setting, I think the best solution for me would be to have separate workspaces fo...