Configure different versions of the same Grails application - grails

By default Grails uses the following locations to look for config files:
"classpath:${appName}-config.properties",
"classpath:${appName}-config.groovy",
"file:${userHome}/.grails/${appName}-config.properties",
"file:${userHome}/.grails/${appName}-config.groovy"
But this leads to conflicts if two (or more) versions of the same application (with the same app name) are runing in the same servlet container. I need this for testing.
How can I use different config files for two Grails applications with the same name in the same servlet container?

Maybe by Externalize Your Grails Configuration.
Here is a good link : externalize grails configuration
I hope this help.

Related

How to deploy multiple Grails 3.x applications in Tomcat 8 with shared jars?

I want to deploy few Grails 3.x web applications in Tomcat 8 with all commons jars in a tomcat/shared/lib directory.
Found similar question How to deploy multiple applications in Tomcat, share jars and have different datasources? but this is having information about Grails 1.x and 2.x versions?
Can someone help me with Grails 3.x and Tomcat 8+ versions?
With lot of research, I finally found a way to have shared libraries for Grails 3 app deployment on Tomcat 8.5.x.
I have explored the resources element in Tomcat context.xml and where we can add external Jars to webapp classloader using JarResources tag. This way we can have all jars in one shared location and all applications having them in webapp class loader.
https://tomcat.apache.org/tomcat-8.5-doc/config/resources.html - Follow this link for more info.

How to integrate moskito-java (monitoring-tool) into a grails application?

I would like to use moskito monitoring within my grails 2.3.9 application.
I already added the dependencies for moskito and the webui into BuildConfig.groovy
compile 'net.anotheria:moskito-core:2.4.2'
compile 'net.anotheria:moskito-aop:2.4.2'
runtime 'net.anotheria:moskito-webui:2.4.2'
runtime 'net.anotheria:moskito-web:2.4.2'
runtime 'net.anotheria:moskito-webui-jersey:2.4.2'
I also marked the classes i want to monitor with the #Monitor annotation.
Now i need to get access to the moskito-webui. I need to add a servlet filter to the web.xml of the grails application (regarding to the documentation). I just installed the grails templates with grails install-templates and modified the web.xml file but i can't get access to the webui of moskito.
Does somebody know how to create an urlmapping or servlet filter for moskito webui within grails? How to integrate it correctly?
if you upgrade to 2.5.0 you don't need an embedded webui, instead you can use a standalone tool called MoSKito Inspect (actually same as WebUI, nicer name).
First add
moskito-inspect-remote
to your dependencies. This jar includes a web-fragment that starts a local listener on RMI port 9041 (port can be altered later).
Second: Download or build your own MoSKito Inspect (take tomcat7 and drop in http://search.maven.org/remotecontent?filepath=net/anotheria/moskito-inspect-standalone/2.5.0/moskito-inspect-standalone-2.5.0.war or build from github source).
Download link is:
http://www.moskito.org/download.html
Third: start your application and MoSKito Inspect. Enter in quickconnect localhost and port 9401. You should see your annotated classes now.
If you have further problems you can also use moskito mailing list: moskito-users#lists.anotheria.net
regards
Leon

Why to use JBoss for Grails deployment?

I'm working on the project that uses Grails as Web framework and JBoss for deploying web-applications. JBoss allows to configure connection to database and then Grails could use JNDI datasource. However in our project we don't use JNDI datasources, we configure data sources for both development and production in DataSource.groovy. Other JBoss services are not used also.
I understand that if we are using JNDI datasource connections then we may benefit if several grails applications are deployed, because in this case there is no need for each grails application to establish its own connection.
So I wonder is there any sense to use JBoss instead of, say, Tomcat or Jetty, if not using it's services?
JBoss is a J2EE container. Compared to Tomcat which is a Servlet and JSP container only, the JBoss AS has a lot more features. Thus JBoss is also "heavier" than Tomcat, and depending on the size of your project this may not fit well with your development team since it has a longer development cycle (I heard there were a lot of improvements in JBoss 7, haven't tried it yet though.)
If you are not using any of the J2EE container features (JMS, EJB, etc.) then you could be fine going with Tomcat using a grails application. We use Tomcat at work for hosting one of our web applications.
In regards to connection pooling managed by JBoss, Tomcat can also do that. Take a look at this documentation page. Hope this helps.

Different log files for Grails applications deployed within one servlet container

I have 2 grails applications packed with --nojars parameter in grails war command. All grails framework libraries are moved to server and they are loader in shared.loader line in tomcat servlet container.
My question is, how can I set different loggers for this different application.
Now log4j = {..} produce the static variable which is shared between two applications.
I'd like to have different logs for each one.
When deploying the war files produced by grails build command without --nojars everithing went well, and each application had its own log file.
Any suggestions ?
I think there should be two different web applications as well. If you do not want the duplicate libraries packaged again, just give them a 'provided' scope and make sure they are available in your instance of Tomcat.

New URLStreamHandlers in glassfish

I have a legacy application that I'm trying to port to Java EE. Presently this application calls URL.setURLStreamHandlerFactory() to register some custom URL protocol handlers. This call fails under Glassfish v 2.1 and 3 because glassfish has already registered a factory.
I've tried using the java.protocol.handler.pkgs system property, but that doesn't work for me due to classloader issues. The handler classes are all part of the application and I'm not keen on trying to extract them and put a jar in the container's classpath.
I've got a whiff of osgi bundles - apparently I could write a Bundle that'll deal with the new protocols. I'm not keen on making this web application an osgi bundle (one step at a time! EE first, then osgi if the need arises).
Is it possible to pop a bundle jar in to my WEB-INF/lib directory and have Glassfish load it as a bundle? The bundle will need to import packages from the web applications (another jar in WEB-INF/lib or in WEB-INF/classes). I'm willing to package this app as an EAR if that'll work, I just can't justify osgifying the entire application without knowing more.
I've solved my issue. Apparently I had some wires crossed as the java.protocol.handler.pkgs system property works fine.
For any one else tripping up, I put a jar with my handlers in $DOMAINDIR/lib/ext/ as well as in my WAR's WEB-INF/lib directory. In my application's configuration I've also put a jvm option -Djava.protocol.handler.pkgs=my.handlers.pkg.prefix
I've noticed in glassfish 2.1 it works without the jvm option if I put the prefix in to some startup code, but in glassfish 3 the jvm option is necessary because felix (the osgi implementation glassfish is using) only consults the property upon the server startup, not for each request.

Resources