Why to use JBoss for Grails deployment? - grails

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.

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.

Do I need to install Tomcat and MySQL on the Linux server to deploy Grails app?

My Grails app is based on
Gradle with Grails 2.4.4,
Tomcat plugin 7.0.55,
and MySQL plugin(mysql:mysql-connector-java:5.1.29).
Do I need to install Tomcat on the server?
Do I need to install MySQL on the server?
Both Tomcat and MySQL are not installed on dev environment(on my PC), but it seems working.
Container
While all the other answers pointed out, that you need already a container (which of course is true) there is also the option to use one of the "standalone" plugins (like e.g. https://grails.org/plugin/standalone). This will package your app as a fat jar, where the container and your app are part of a jar, that you simply run by java -jar myapp.jar (of course your would integrate that into your regular startup scripts on the server).
This is in general no bad option, since many WAR-deployed apps don't need any of the full blown container features anyway and you would be able to configure everything in place for your workload and don't have to compromise for all running wars (or your ops team). On the downside, if there is a security problem etc. with the container you would have to roll a new jar.
/With grails 3, which uses Spring Bootstrap, this even is a default option, since the preferred way of deploying. Spring Boot 1.2 supports Tomcat, Jetty, and Undertow by default./
Database
You can use a MySQL from "somewhere" else. But this is nitpicking, since you really need a MySQL somewhere (BTW: you really should start using MySQL also for your dev env, or you will be in for a few surprises once you put your stuff over to production).
Also be aware, that you can also keep using your H2 (see your datasource config) with files. This is an OK option (that saves you from installing a DB server) for small amounts of data you are storing and also there are other free database servers like PostgreSQL.
Obviously you have to install mysql and tomcat on the server.
During development you run grails from console, so you dont need tomcat as it will use embedded tomcat but still you need to have mysql installed, if you want to use mysql.
But on production, you create a war of your app using 'grails war command' and you deploy this war to a web container just like any other war, so you need tomcat and you will need mysql installed too.
In one word answer is 'Yes'.
Fact is when you are in development environment grails uses as an embedded tomcat server provided by the 'Apache Tomcat plugin' which version corresponds to grails version.
You've not installed mysql and you claimed 'it seems working'. That's funny! But it's not mysql who is working without being installed(!), rather it's also an integrated database provided by the 'H2 Database Plugin'.
So, when you'll deploy your grails app in Linux or another server certainly you need a tomcat server to handle user request to that app and a database where your data will be saved.

How to correctly export a JSF 2.0 web application into war?

I have a JSF 2.0 web project and I use Glassfish 3.1.2 server. In this project, I have among other things :
a class called AjaxServlet annotated with #javax.servlet.annotation.WebServlet
a class called Session annotated with #javax.ejb.Stateful
When I deploy this project to Glassfish from eclipse, everything runs perfectly : in the administration console of Glassfish, the engines associated with the application are [ejb, jpa, web, weld]. But when I first export the project as a war, then from the admin console I deploy the war, the application doesn't work : the engines associated to the application are then [web] only.
How can I export an application to a war without loosing any information (all the engines)? I didn't declare my Servlet in web.xml because in JSF 2.0, we don't need that: the annotations are enough. Does anyone have an idea about what is going on here? I'm quite sure it is not a problem of Glassfish distributions (Web Profile Vs Full Platform) as the same Glassfish server is used for the 2 scenarios above.
Note for those who erroneously think my question is off-topic : Jsf is a framework for programming Java EE web applications. war is a way to package a Jsf application, in the same as jar is a way to package java classes. So my question is totally a programming topic! It is totally legitimate to have it here in StackOverflow. If exporting JSF application into war is not a programming issue, then compiling java classes into .class should not be a programming topic neither! So Pleaze don't downgrade for this reason!
You have to understand the difference between your eclipse environment and your glassfish environment. Not all your libraries that are available in eclipse might be included in your external environment. There are cases where programs compile in eclipse, but not when run from console.
Here's a tip:
Right click on project -> Navigate to Properties > Java Build Path > Order and Export, and ensure that all libraries you require are going to be exported.

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