Deploying Grails To Tomcat Resulting in 404

In the previous post, I was able to set up an EC2 instance in AWS that mimics the Elastic Beanstalk setup.

The next step is deploying the Grails app into this instance.

I did the WAR deployment into Tomcat route, which involves:

  • Bundling the app into a WAR file via grails prod war.
  • Uploading the WAR into the EC2 instance.
  • Copying the WAR file into /usr/share/tomcat8/webapps and renaming it to ROOT.war
  • Restarting Tomcat.

As expected, Tomcat expanded the WAR file into ROOT folder. However when I access the Grails URL, I received a 404 error, with the following details:

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

I was perplexed, I couldn’t really work out what I did wrong and the error message was cryptic to me. Luckily, I found this: Grails war on Tomcat 7 results in 404.

Java version matters

From the GitHub issue above, it turns out: the Java version used to create the WAR and Tomcat server’s Java version matters.

I compiled my WAR on my laptop which has Java 8. However I uploaded it to EC2 with Java 7.

When I updated the Java version on the EC2 server, the problem is solved! Yay.

To update the Java version on EC2 (Linux based of course):

sudo yum install java-1.8.0
sudo yum remove java-1.7.0-openjdk

Happy hacking!