This tutorial is originally from http://smithnicholas.wordpress.com/2010/09/20/deploying-your-grails-application-on-eatj/
In this post I’m going to show you how easy it is to host your Grails application online. People also have a perception that Java hosting is expensive, and it can be; however for low use applications and initial production proving, a budget one should suffice.
So you’re at the stage where you’ve finished initial development your Grails application and now it’s time to get it online for the world to see. You’ve cast your eye over
http://www.grails.org/hosting and EATJ is the one that catches your eye; as it’s the cheap – like the budgie. At $9.85 per month, this is pretty good value for Java hosting, and gets even cheaper if you plump for a year term, $8.21.
So let’s have a look at what’s involved:
1) Register with EATJ
As you can see EATJ lets you create an account for free, sadly that’s all it lets you do. After you have verified your email address you will be asked to “pay for your free trial”, your also instructed to contact customer support for a refund after your trial. I guess this is basically equivalent of a money back guarantee.
After paying via PayPal or credit card you then have email firstname.lastname@example.org with your username.
Yes, wait; after emailing customer support it took a mere three and a half hours to activate the account.
3) Set up MySQL Workbench
Your EATJ console comes with links to phpMyAdmin, which is fine if your not planning to ferret around the database much, but likely you will need a half decent browser. Obviously you can use TOAD or whatever floats your boat though.
You need to check you server address in your welcome email, and careful of the port, the default one is usually 3306. Once you have connected to the database you know you have the correct settings for the next step.
Now put your newly determined database settings into datasource.groovy.
dbCreate = "update"
url = "jdbc:mysql://localhost:3307/username?autoReconnect=true"
driverClassName = "com.mysql.jdbc.Driver"
username = "username"
password = "password"
Change the dbCreate property if required, but as a production environment I can’t really see this being any different. Update your username and password as necessary; password is by default in clear text. If you want to encrypt the password, the clearest instructions I have found on how to do this are attached to this JIRA, there also this Release Note.
I assume at some point you would have carried out local testing on MySQL and therefore have the JDBC connector on your classpath. If not, you should get the latest version from MySQL, then simply drop the jar into your lib folder.
You need to add the root of your production application to environments block in the config.groovy file, like with the other environments is needed for relative paths in your application.
grails.serverURL = "http://username.s11.eatj.com/appname"
In the example above I’m using the sub domain that EATJ provide, check your welcome email carefully though as “s11” may be different. If you want to use your own domain you can add one after logging in to your EATJ console at eatj.com, you’ll also find out the ns setting there too. Adjust your root accordingly.
6) Create a war
Now you’ve updated your production settings simply run the war command from the grails console
grails war. This should then deposit the war in the target folder of you application, and will be given the name and version provided in the
application.properties file. i.e.
7) Upload the war
You have two choices for uploading your war now, you can either use the up-loader from the EATJ console from logging in at eatj.com, or you can hit the Tomcat manager directly:
http://username.s11.eatj.com/manager/html . When asked for credentials, username should be “admin” rather then your account username, but the password will be the same as your account one.
8) Check out your application
That really should be it! It’s fair to say, when I started taking notes during the process I expected to encounter a few more steps and ultimately describe a more involved process. A real testament to how easy it is to deploy a Grails application in the wild. In fact the longest part of the whole process is waiting for EATJ to activate the account!
Its worth mentioning a couple of minor issues though; perhaps more specific to my circumstances:
Get working on local tomcat first.
Interesting point here; be careful of your references in your gsp files. Jetty seems to be case-insensitive when developing in Windows, and therefore in running a Grails application in a dev set-up will hide potential errors. For example I was calling a template:
The actual file name was
_templatename.gsp; an error on my part that was being hidden by Jetty in development. There does appear to be an open JIRA to address this though; worth keeping an eye on. In the meantime I recommend before uploading your war to EATJ you deploy it to a local Tomcat instance and touch each page.
Delete your tables, mine still had data!
Rather lazily and (irresponsibly), EATJ don’t appear to appear to clear down the environments very carefully. The one I was assigned had a database schema (complete with data) from a previous owner. Make sure you drop any tables that shouldn’t be there when you get an account. Similarly I’d make sure you drop all tables if/when you leave EATJ; particularly if they have people’s personal data!
So far I have no other complaints about the EATJ service; although it is fair to say I haven’t stressed it. If you can see past the ropey sign up process and poor housekeeping it seems to be good value.
More tutorials: http://jsptutorblog.blogspot.com/