Add a <servlet> into web.xml in Grails 2.1 - grails

I want to add a node into web.xml.
I tried to use a webxml grails plugin, but look like it can't manage nodes. Any help or example will be apreciated...

You can use your own web.xml, with any content you want. Run
> grails install-templates
and edit /src/templates/war/web.xml file (it's a template, so don't remove existing Grails code)
See http://grails.org/doc/latest/ref/Command%20Line/install-templates.html

I'm not able to add comments yet, so here it goes.
By looking at your last comment, I suppose that you were looking for grails:exec:
mvn grails:exec -Dcommand=install-templates
Many Grails commands don't have the equivalent wrapper exposed directly through Maven.

Related

[grails 3]: Replacement of doWithWebDescriptor on Plugin descriptor?

We are trying to move our existing grails 2.5 application to newer versions of grails. For that adopting strategy to first upgrade to grails 3.3.11 (latest in 3.x releases) and then move to grails 4.
For one of the feature from grails 2.5.6 application, I found that there is nothing documented anywhere or may be I've missed that part on the document! It is about Plugin descriptor's doWithWebDescriptor. With this closure we can able to update web.xml dynamically based on some rules.
After upgrading to grails 3, I found that doWithWebDescriptor is not working. It is not initializing task which it supposed to (as far as grails 2.5 concerned). Later I found that there is nothing documented after grails 3.0 documentation.
If doWithWebDescriptor is removed then what is the best suitable replacement with grails 3 or latest grails 4 edition? If it still working fine and there is some configuration related changes required with grails 3 then kindly point me to that part.
Update:
Reason why we need doWithWebDescriptor is that, we are trying to add servlet based on the plugin. Actually we have several plugins for different modules in the application. Not all plugins included in the project. Based on modules selected we are adding plugin to the application. So if a plugin is included then we need to add servlet and a filter to web.xml.
Thank you.
Reason why we need doWithWebDescriptor is that, we are trying to add
servlet based on the plugin.
You can add a servlet by registering a ServletRegistrationBean in the application context. You can do that in the plugin's doWithSpring method or in the app's resources.groovy. Example:
Closure doWithSpring() {{->
myServlet(ServletRegistrationBean, new MyServlet(), "/myServlet/*") {
loadOnStartup = 2
}
}}
We have documented this in the 18.5 Hooking into Runtime Configuration section at http://docs.grails.org/3.3.11/guide/plugins.html#hookingIntoRuntimeConfiguration.

Grails3.04, what is "f:table"?

grails 3.04
generate-all mydomain
index.gsp
what is "f:table"?
I can't find it in grails 3.04 document.
I can't find it in https://github.com/grails-fields-plugin/grails-fields.
What is this magic? How can I get to learn it?
I'm sorry, I don't have the ability to write English.
Translation support:http://fanyi.youdao.com/
The tag f:table you are referring to comes from the fields plug-in, as you correctly noticed. It is used to render some (or all) properties of a list of beans (Domain Classes for example) as a table.
You pointed to the documentation of the fields plugin for Grails 2.x. The fields plug-in has been forked to make a version for Grails 3.x. Have a look here for the documentation: http://grails3-plugins.github.io/fields/snapshot/ref/Tags/table.html

Include more than one filter from existing JAR into a Grails project

I have a Grails project and want to add existing filters from a JAR file.
I used the WebXmlConfig plugin, mentioned in this answer:
How to add filters to a Grails app
and that worked great for a single filter, but I can't figure out how to extend that to more than one filter.
Do I need to change approach and edit the web.xml template directly?
I'd use the pluginator plugin and put the definitions in doWithWebDescriptor just like you would in a plugin - you can add as many elements as you want. It's a slick plugin that lets apps do things that are generally only supported in plugins, like conveniently editing web.xml (although with a seriously weird DSL) and registering custom artifact types.

How to add filters to a Grails app

I'm trying to add these single signout filters to my Grails 2.3.6 app. According to the Grails docs on Filters it seems like you can only add new (custom) filters to Grails apps, whereas these are existing filters imported from another project/JAR.
I scanned my project for the existence of a web.xml and didn't find anything.
How can I add the specific filters in the above link to my Grails app?
The easiest way is to run "grails install-templates" and edit the resulting src/templates/war/web.xml file.
You can use WebXmlConfig plugin which provides a DSL approach to add/modify contents to web.xml.

Is it possible to add Grails MVC classes at deployment time?

I'm writing a Grails app which I'd like 3rd parties to augment at runtime. Ideally they would be able to add a JAR/WAR to the webapp directory which contains new domain, controller and service classes, new views, and other content.
Is there a simple way to do this within grails? Would it be simplest to create a startup script which copies the new classes etc. into the relevant directories and then updates grails.xml and web.xml?
You will be able to do this in version 2 of grails in which plugins will be also OSGI plugins http://jira.codehaus.org/browse/GRAILS/fixforversion/15421
It seems that the Grails plugins will actually fit quite well for this: http://www.grails.org/Understanding+Plugins
A plugin can do just about anything... One thing a plugin cannot do though is modify the web-app/WEB-INF/web.xml or web-app/WEB-INF/applicationContext.xml files. A plugin can participate in web.xml generation, but not modify the file or provide a replacement. A plugin can NEVER change the applicationContext.xml file, but can provide runtime bean definitions

Resources