Gunnar's blog - Operations

Which Framework is Best for a Simple Web App?

Choose the most straightforward way to make a web application in Java

Lots of people want to wet their feet with web development by building with Java. The trouble is that Java presents an overwhelming number of frameworks. It's easy to go round and round in circles, stuck in analysis paralysis. They read about JavaEE, then servlets. Someone on a forum says Spring is better. A flamewar erupts between Play and Grails.

What should a person do?

I think the most important thing to do, when faced with overwhelming choices, is to pause and step back. Take a deep breath! Go for a walk away from the computer. When you come back, dig into what your intent really is. In this case, you want to make a simple web app. "Hello world" in Java, but on the web.

I suggest choosing the simplest option, which is vanilla Java servlets. Don't bother with a framework until you know the application is complex enough be worth the overhead. After you've made your simple servlet, build a war, deploy it to Tomcat and call it a day.

That said, if you must use a framework...

Use Dropwizard

Java has a reputation for being heavyweight and verbose. It doesn't have to be that way. Dropwizard takes a lot of verbosity and enterprise-yness out of making a web application (especially compared to Spring). I'm a fan, and if you're hellbent on using a framework, try out Dropwizard.

Why use Docker When You Can Just Use a Fat Jar?


I saw a question on r/java that I thought was great. OP is deploying a fat jar that has everything OP's app requires, so the deploy is just a simple file copy. OP is also using Docker to deploy the entire environment along with the jar and wonders if it is worth it.

When to Use Docker

Docker is great when you are using Docker to deploy your entire server environment. If you have already container-ized your database, proxy and load balancer, it's a no brainer to add just one more docker image to container-ize your application. Your team already has the Docker infrastructure in place. Your environment already deploys with Docker. Unifying procedures keeps things simple.

3 Reasons to Use Docker

  1. Your application shrinks and grows. Adding/removing instances helps keep the bills down and the customers happy. This is particularly important on providers like AWS and DigitalOcean
  2. You deploy your application to a lot of different environments. Each different environment needs a couple tweaks to work.
  3. You don't want your deployment process to care about the state of server upgrades (like the JVM or Tomcat)

When to Use a Fat Jar

Fat jars are great. A fat jar bundles everything you need into one convenient archive, ready to go. Deploying a fat jar is easy: copy the jar to the server and run it. It's worth pointing out that fat jars combine very well with Docker - they are easier to use in the Docker context than containers.

3 Reasons to Use a Fat Jar

  1. When your environment is hand crafted. Fat jars are particularly useful both the jar and the environment define configuration
  2. When maintaining a Docker registry is significant overhead. If you're not already doing it, why add yet another infrastructure system?
  3. When you have an artifact repository (like Archiva or Nexus). These make it trivial to grab and deploy a particular version of your fat jar

Page 1 / 1