Tomcat Maven plugin and multi-module Maven projects - maven-3

We have an application that until recently was a single Maven WAR project. We were using the Tomcat Maven plugin to run the application on local developer workstations using:
mvn tomcat:run
We were able to change JSP files while the embedded Tomcat instance was running and the changes would appear in web browsers just fine. I understand (from the plugin documentation) that when using the tomcat:run goal, the WAR is loaded as a dynamic web application and hence changes made to JSP files at source are picked up by Tomcat at runtime without restart.
The application has reached a fairly large size and we needed to reuse a large number of classes in a few different places besides the web project, so we refactored the code base into a multi-module Maven project. The structure is now:
parent Maven POM
|
---- artifact1.jar
|
---- artifact2.jar -> depends on artifact1.jar
|
---- artifact3.jar -> depends on artifact1.jar
|
---- artifact4.jar -> depends on artifact2.jar and artifact3.jar
|
---- artifact5.war -> depends on artifact1.jar, artifact2.jar, artifact3.jar and artifact4.jar
After the refactoring we were unable to use tomcat:run from the project's root directory to run the WAR project as the plugin was unable to detect the JAR artifacts. So, we switched to using the tomcat:run-war-only plugin. The WAR module now launches fine.
However, from the documentation, it seems that the run-war-only goal treats WAR files as packaged web applications. Therefore, any changes we make to JSP files now are not picked up by the embedded Tomcat server while running. For every change to JSP files we have to restart the server.
Is there a way for us in this multi-module Maven set up to run WAR projects as dynamic web applications so that at least changes to JSP files are picked up by Tomcat without restarting?

Just do an mvn install first and then
mvn -pl artifact5 tomcat:run

First use new version of the tomcat plugin now located at Apache see http://tomcat.apache.org/maven-plugin-2.0/.
Then if you use maven3, you simply use tomcat6/tomcat7:run from the top. All classes from modules will be added to your webapp classloader (will save some ios as you don't need to install all jars first !) see http://tomcat.apache.org/maven-plugin-2.0/run-mojo-features.html
HTH!

Related

Resolving view from webflow when running app with run-web

I have grails app that uses plugins to modularize app. Structure of app is as follows:
pluginA
pluginB
pluginMain
On one of those plugins (say pluginA) I have controller that uses Spring Webflow (using Spring Webflow 2.0.8.1).
Plugins are resolved locally in BuildConfig.groovy of pluginMain (grails.plugin.location.'pluginA' = "../pluginA"
grails.plugin.location.'pluginB' = "../pluginB").
When running app with run-app views used by webflow are resloved OK.
But, when I run app with run-war controller from pluginA tries to resolve view from location pluginMain/WEB-INF/grails-app/views/controllerName/flowName/nameOfView.jsp instead from pluginA
so I am getting HTTP 404 not found error.
I am using grails 2.3.7 and java jdk 1.7.
Please help!
The location that it is looking for in the run-war situation is the standard location for resolving page and flow views. You are likely getting into trouble by attempting to create a war file using inline plugins (the grails.plugin.location).
The inline plugin support is really nice when developing plugin functionality, but it has its quirks, particularly when you get multiple dependent plugins in play. At some point you have to break down and start publishing your plugins.
Try publishing the plugin to your local Maven repository using the "maven-install" command. Then change your BuildConfig.groovy file to reference the installed version of the plugin.
My normal workflow is something like this:
Develop the new plugin functionality using an inline plugin definition in BuildConfig.groovy, testing with run-app and run-test until I'm happy.
Publish a SNAPSHOT version of the plugin (ie. 1.0.1-SNAPSHOT) and update BuildConfig.groovy to point to the snapshot and test using run-app and run-war eg:
compile (":ark-kpi:1.0.1-SNAPSHOT")
Publish your plugin in release form either to your local maven repository (maven-install) or a public repository like a locally running Artifactory if you want to share with colleagues (publish-plugin).
You should read the guide section on plugins and configuration for details on setting up repositories.

How do I create a Grails skeleton project for plugin development?

I am working with a (sort of) framework built on top of Grails. This framework is a set of Grails plugins that add functionality to the Grails app (e.g. user authentication). This framework is a bit of a pain to setup, as it requires around 64 lines of site specific configuration in the apps's Config.groovy file.
I want to develop my addons to this app as plugins. That is, the Grails app would really just be a set of installed plugins and some configuration files.
I have created a local Maven style repository to hold all of my plugins. Thus, I can add plugin dependencies to the BuildConfig.groovy file and they will be installed automatically (side question: is it possible to specify the install order?).
So my question is, how do I create skeleton project for developing my plugins that would:
Include the base configuration for my application (the aforementioned 64 lines)
Allow me to do a grails package-plugin to package only the plugin's code
You can use the post-installation hooks mechanism: http://grails.org/doc/latest/guide/plugins.html#hookingIntoBuildEvents
Not really an ideal setup for me, but the following works:
Create the "base" application: cd ~/GrailsDev/ && grails create-app my-app
Configure my-app as desired/required
Create your dependent plugin: cd ~/GrailsDev/ && grails create-plugin my-app-plugin
Add the new plugin to the app by editing "~/GrailsDev/my-app/grails-app/conf/BuildConfig.groovy" and appending the line: grails.plugin.location.'my-app-plugin' = "../my-app-plugin"
You can now run the my-app Grails application and the plugin will be included. When your plugin is fully developed, you can do grails package-plugin from within the "~/GrailsDev/my-app-plugin" directory to package your plugin.
use gradle. you can specify the order and package your plugin alone.
e.g. include the required plugins as git modules (for easy versioning) and gradle modules (for building your plugin) in your plugin project.
this setup will serve your requirements well I suppose.
https://github.com/grails/grails-gradle-plugin
IntelliJ does have a template for gradle-backed grails applications and plugins.

Grails + Tomcat6 + Multiple Instances + Shared Lib Folder

I've got a Tomcat6 server that runs multiple Instances for two separate grail apps.
When I compile my WAR file for deployment normally
run-app -Dgrails.env=production war test.war
It deploys correctly and everything works as it is suppose too.
The problem is, I don't want the JAR files included in my WAR.
So I use the following command line instead
run-app -Dgrails.env=production war test.war --nojars
Now when my grails app deploys (it doesn't) I get a java.lang.NoSuchMethodError
I have copied the lib folder (from my initial test.war) to the following locations
${catalina.base}/shared/lib
${catalina.home}/shared/lib
${catalina.home}/lib
None of these work.
My catalina.properties all point to the correct locations.
Any ideas?
A few ideas:
BuildConfig.groovy has inherits global, which has the app inherit all of the grails/plugins dependencies. If you change this, it may affect both your build and packaging - plus I have yet to encounter any documentation on what type of other things you can do with the inherits DSL
Grails deployment documentation suggests there is a way to customize which dependencies make it into the war file: http://grails.org/doc/latest/guide/17.%20Deployment.html
Event hooks give you access to provide a closure routine into various stages of the grails lifecycle. Can it strip out framework jars from the final war? Haven't tried that either - only using it to re-write various config files for additional envrionment configuration. However it does look like packaging events are exposed to this API:
http://grails.org/doc/latest/guide/4.%20The%20Command%20Line.html

GRAILS + Eclipse Project Dependencies

I am working on a Grails project that consists of a master grails-app and several grails plugins. One of the grails plugins is “Core” and contains several groovy and java domain and utility classes. Currently the core project is a grails plugin, however I’d like to pull the sources out of src/groovy and src/java into a Groovy class library that I’ll eventually package into a jar file.
I’d like to understand how to get this set up properly in Eclipse so that the plugins reference the new Groovy library and the application references the plugins and everything builds ok.
If I spin up a grails plugin, and then add the groovy project to the build path using eclipse, I can get the plugin to build fine. The issue is, now I add a plugin reference from the grails web application to this plugin and the grails application won’t build. I have added the Groovy library to the build path of the web application, but when grails tries to add the plugin it complains that it doesn’t know about the classes in my groovy library.
Here’s the project structure
server-core ( groovy project )
ia-security-plugin ( grails plugin project ) ( server-core is on the build path , builds fine )
server-core-web ( grails app project) ( references ia-security-plugin in Build.config ) ( won’t build )
During development add the following line to your BuildConfig.groovy
grails.plugin.location.'plugin-project'="../PluginProject"
where PluginProject is the eclipse project relative to your current project and plugin-project is the name of the plugin project. This takes the pain of rebuilding your plugins and all reference problems. You can even step debug through your main project into the plugin project.
For deployment time I have setup Artifactory with Maven Repository ID (on the plugin project) and [Main Project] BuildConfig.groovy to
compile (":plugin-name:latest.release")
along with
mavenRepo "http://location-of-local-artifactory/
Use http://grails.org/plugin/release for release management and repository setup.
Hudson automatically picks up the plugin and builds the war file on the build machine.
Alternatively you could simply build the war file and deploy to the server if your project is composed of just few developers.

Set a different classpath for just one grails command

I need to set a different classpath for one single grails xxx command.
The point is that my application uses latest version of commons-httpclient. I have no problems with this. But after building my application I need to use grails maven-deploy to store my war file in a webdav repository, and the command conflicts with the latest version of commons-httpclient. This command works great if I add commons-httpclient-2.0.2.jar in the classpath (lib folder for example), but the app will fail on trying to use the regular features that depends on commons-httpclient.
I need to add this other jar in the classpath just for running the maven-deploy command, any ideas?
I'm using jenkins (huson) to build the app, so, any tips on making the solution achievable with grails jenkins plugins will be appreciated.
Thanks a lot,
Does the grails maven-deploy command conflicts due to another dependency on httpclient?
Which one is it? May be you could exclude the dependency it?

Resources