I created a trivial Grails 3.0.1 application and loaded it into IntelliJ IDEA by importing the build.gradle file. The recommended way to run the app through IDEA is to execute the Application.groovy class in the init folder.
Doing that started the app, and I was able to browse to the "Welcome to Grails" page, but when I tried to access any of the controllers I get:
This page contains the following errors:
error on line 7 at column 12: Opening and ending tag mismatch: meta line 0 and head
Below is a rendering of the page up to the first error.
default.list.label
in the browser. I have two domain classes and generated the controllers and views using generate-all.
I think something is failing in the <gsp> tags, but I don't know what.
If I start the application using grails run-app, the views work properly, so this is specifically an issue with Application.groovy.
Related
I'm using Intellij Idea IDE to build Grails 3 web apps, whenever I do Rebuild project the actions in controllers starts throwing 404 errors, I checked the URL Mapping and found no issues with it, in order to make these actions work again I need to open controllers and do some changes and then click on "Make", can anyone suggest a solution for this?
I'm using Grails 3 and using a template _displayWidget.gsp to show certain parts of the show view differently.
All works fine when running the application directly, but when I build the war (using gradle assemble) and deploy this (on a tomcat 7) my own written _displayWidget.gsp is not used anymore. Anyone has an idea why?
Use grails war to create your war.
First I'm new to grails as well website development.I started grails project and studying.
I'm clear about grails concepts like Domain class, controller, view, agile development like this.
While executing grails run-app command, at which point does grails start execution in the framework and run (like main() method in Java)?
Which is the first entry place domain or controller or view or main.gsp in my project from where it is coming from grails framework?
When server starts up, Bootstrap.groovy is executed.
For listening to each request you probably would need to define your own filter.
However the very beginning of every request is the org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.
When a request comes in, grails determines the controller and the action (based on the URL and any UrlMappings you've specified) and calls it. So from your application code's point of view, the starting point is one of your actions.
For example:
If a user requests http://abc.com/book/list, where abc.com is your site, the method def list() in your BookController.groovy is the starting point.
Internally, grails calls each closure in AppFilters.groovy (and other filters defined by you or the plugins you are using) if any before calling your controller's action. If you are developing a very simple app, those wouldn't matter.
Grails incorporates the powerful build system Gant, which is a Groovy wrapper around Apache Ant.
When you run the command : Grails [commad-name],
Grails searches in the following directories for Gant scripts to execute:
USER_HOME/.grails/scripts
PROJECT_HOME/src/main/scripts/
PROJECT_HOME/plugins/*/scripts
GRAILS_HOME/scripts
When you execute Grails run-app command, It will execute the file RunApp.groovy file from above mentioned paths. These are groovy files, once you look into files, you will understand the code inside that.
I have a plugin with domain, controller and view pages. (Using grails 1.3.6)
I run the plugin as standalone, the views work fine. URL: http://localhost:8080/sample-plugin/gp/list. I am able to view the list page.
I installed the plugin into a main application i.e. plugin-test. Start as run-app within STS and browse to http://localhost:8080/plugin-test/gp/list. I am able to view the list page.
I bundle the application as war i.e. plugin-test.war and deploy to tomcat. When I browse to http://localhost:8181/plugin-test/gp/list I get a 404 error! I am not sure what I am doing wrong.
I have been trying to resolve it for quite sometime now and still no luck. The same main application works fine in STS but not in tomcat.
HTTP Status 404 - /plugin-test/WEB-INF/grails-app/views/gp/list.jsp
type Status report
message /plugin-test/WEB-INF/grails-app/views/gp/list.jsp
description The requested resource (/plugin-test/WEB-INF/grails-app/views/gp/list.jsp) is not available.
Please help.
Thank you.
Jay Chandran.
This sounds worryingly familiar, as I spent a while figuring out this (or a very similar) issue. I ended up raising this Grails bug report:
Plugin layout not found in war when installed from BuildConfig.groovy
Have you installed the plugin as using the new BuidConfig dependency technique? The JIRA documents my workaround.
Sharing some of my lessons learned after experiencing the same exact issue (1.3.7):
Double check your HTML source to make sure that your template really isn't being included. Mine was being included, but my CSS/image URLs were wrong (only while running as a war)...so I wrongly assumed that my template wasn't there.
Don't use the ui performance tags for referencing your static content...doesn't appear to work, even if the plugin attribute is specified.
Don't name your layout main.gsp. You're guaranteed to have conflicts.
Don't use absolute=true on your g:resource tags. This doesn't appear to append the pluginContextPath to the absolute url, even if you specify dir="${pluginContextPath}"
Don't use pluginContextPath, as it's no longer required: http://grails.org/doc/latest/guide/single.html#6.3%20Tag%20Libraries (search "Plugin Paths")
In your g:resource tags in your plugin layout, make sure you specify the plugin attribute. Set it to the name of your plugin.
Move your static images/css from your plugin to a web server. If each application using your plugin has its own copy, your users aren't going to benefit from caching when bouncing between apps.
Note that all of the above applies to the layout gsp in your plugin project, not your consuming application.
I created a grails plugin in which some domain classes, controllers and views were added. After creating the plugin, I imported it in a grails application by using "grails.plugin.location.'...' = '.....'" in BuildConfig.groovy.
Everything is okay when the application starts up. And, everything is nice when online modifying the view GSPs in the plugin.
But, when I modified any controller in the plugin, the grails cannot find the view files corresponding to the modified controller in the plugin. Tomcat reported "HTTP Status 404" error. And, everything becomes okay again after restarting grails.
I am using Grails 1.3.3 and Groovy 1.7.2.
After googling, I found it was an unresolved bug. Please refer to the following URL:
http://jira.codehaus.org/browse/GRAILS-5869
In the bug page, there is a workaround reported. You can add annotation for the controller class of your plugin to make everything okay. Following is an example:
import org.codehaus.groovy.grails.plugins.metadata.GrailsPlugin
#GrailsPlugin(name='...', version='...')
class ... {
....
}