Java MVC Frameworks Comparison
Web frameworks are all very different; typically they have been created for different reasons and to achieve different goals. Which Java web framework will you use in your next project and why would you chose one over the other? There are many features which may sway your decision and of course it will depend on the type of app you’re building. This Java MVC frameworks comparison will simplify comparing eight popular Java MVC frameworks.
What Is a MVC Framework in Java?
A MVC framework follows the Model-View-Controller pattern. In an MVC framework, the three "layers" separate the user interface from the application logic.
MVC frameworks are used to control how information is represented internally versus how it is presented to the user. MVC frameworks are popular for a variety of programming languages, including Java.Back to top
Why Do We Need Web Frameworks?
It can be difficult to code good-looking web applications, and doubly so to create a rich front-end experience for users. These challenges have been the catalyst for creating web frameworks.
But Java web frameworks are not one-size-fits-all. Functional and non-functional requirements have in turn led to the creation of myriad web frameworks. With so many to choose from, which web framework should you pick for your next web app? In this blog post, we will take a closer look at eight Java web frameworks and analyze the use cases for each:
Comparing Java MVC Frameworks
It’s important to be able to launch yourself into a new language or project and be productive quickly—and learning a Java web framework is no different.
Let’s compare and contrast each framework based on four criteria:
- Rapid application prototyping
- Framework complexity
- Ease of Use
- Documentation and Community
1. Rapid Application Prototyping
Whether you’re using a Java MVC framework for the first time, or you’re an expert in all things framework related, it’s important to be able to develop quickly to prototype an idea or just try new things out. This section rates each framework for the ability to produce content from scratch with rapid results.
Very few use Spring MVC by itself nowadays with many developers now running their applications with SpringBoot. It mainstreams this process greatly making it very easy to get started with your application.
Next time you need to implement some small-to-medium CRUD application, consider using Grails. The setup is very fast and scaffolding (code generation) saves a lot of time. Convention over configuration principle helps you to forget almost all of the configuration hassle.
The Vaadin directory is a component repository which provides existing components that users have implemented and contributed for others to use. If you choose to use something in the repository, you simply need to download the JAR and add it to your project and use it in your code straight away.
Wicket offers HTML and component structure with no need for configuration files. With its clear MVC model, clean HTML and a wicked component module, you can create new applications with reusable components quickly.
Play has great documentation and the scaffolding works wonderfully. Play has a binary component similar to the Rails component of RoR, which is used for scaffolding. This makes Play a little unconventional as a Java web framework but there’s a low barrier to entry for new developers.
Many Java developers see Struts as a legacy technology, and you must configure a lot to start prototyping. An example project can be a good starting point. On the bright side, Struts has a Convention plugin that enforces some convention over configuration and provides annotations to configure URL mappings.
JSF doesn’t excel at quick prototyping; code generation is not a built-in feature and prototype applications require just as much configuration as a full application. JSF does have several useful Maven archetypes, however, that do provide a good starting point for a basic application. Prototyping can also be achieved with the vast array of sample projects available both online and bundled with many of the Java EE application servers.
2. Framework Complexity
Here, we’ll explore each framework’s construction and discuss how many moving parts exist in each framework and how the complexity of a given Java MVC framework affects you. Do you really want to learn 10 technologies to use a framework? There are also other considerations when choosing frameworks, such as whether the extra features and benefits outweigh the extra complexity levied against frameworks for your application.
The base Spring framework gives a solid foundation for over 22 subprojects. These mature projects range from your “basic” fully functional MVC to Spring .NET and Spring for Android. Spring MVC architecture is relatively simple, but still there are many layers and abstractions that are sometimes hard to debug if something goes wrong.
Grails has all of the complexity associated with Spring and Hibernate, and adds another layer of abstraction to that. Everything is glued together with core Spring. All of these frameworks are mature, but heavy-weight and Grails adds another layer of abstraction on top of it. Grails also tries to be a full-stack framework by having itas own console, build tool and a lot of plugins.
The Vaadin Framework currently builds upon a flavor of GWT (lightly altered), which is a mature framework. The way you’d go about developing a Vaadin project is similar to GWT in the sense that you could create a hierarchy of components, but learning GWT is not a prerequisite to be competent at using Vaadin.
Wicket has clean HTML and a large library of components and a wide range of model objects that the components can use to retrieve or push data. However, the model inheritance can be pretty difficult to grasp initially and, while it increases code reuse, it reduces readability and is unnecessarily complex.
Play is a complex framework with a lot of moving pieces, but that complexity also comes with lots of features, including Netty, SBT, Akka, a Scala templating engine, and several other modules built in. Play emphasizes convention over configuration, so the framework is responsible for scaffolding much of the glue and configuration between the modules, which does cut down on the complexity experienced by Java developers.
Struts isn’t lightweight, but it isn’t overly complex either. When a user request comes into Struts, there is an Action (Struts’ term for a controller) to be performed and interceptors to be invoked before and after the action. Interceptors can manage logging, security, double-submit guarding, etc. The result of the action is rendered using chosen view technology.
JSF is incredibly complex, and that is the largest downfall of the framework. However, this is not JSF’s fault, this is due to the Java EE specification and the inflexibility of runtimes available. There are open-source implementations of the JSF specification that do allow the use of non-Java EE containers like Tomcat, which cuts down tremendously on the complexity of having to run a full Java Enterprise application server.
3. Ease of Use
This section is all about how easy it is to pick up a framework for the first time and play with it, learn and get results. Think of it this way: if you gave one of these frameworks to a colleague, how many questions would you have to answer for them?
Spring is for building serious applications with solid foundations, rich user interfaces and a RESTful API, which makes it completely unnecessary for anything significantly simpler than that. It’s an extensive Java web framework, but requires significant knowledge, even with the considerable advances surrounding setup with SpringBoot and SpringInitializr.
Grails is designed to be a rapid development framework and rapid is a direct consequence of ease of use. It is advocating convention over configuration and doing it right. Extensibility is very simple when using plugins. One considerable downside is that you need to get familiar with Groovy when you learn how to use Grails.
Vaadin takes away the bulk of the GWT boilerplate code away from the developer, which makes it easy to use, particularly from the design view. The design view allows us to drag and drop components onto a canvas and provide the logic code behind each component. The code which creates and sets up the UI for each component is created automatically and can be viewed from source view.
Wicket lets Java developers do what Java developers do best: Java. There is a clear separation of markup (HTML/XML) and logic (Java code), which lets your Java developers worry about the Java and your web designers make changes to the markup templates of an application without worrying about breaking everything. Model inheritance can be a little hard to grasp initially, however.
Play is really simple to get started with, yet has enough complexity for a developer to take full advantage of. One of the best things about Play is the ability to go from zero knowledge of the framework to leveraging some of the more basic capabilities in less than 10 minutes. While simple to get started, the two things that really keep Play from being really easy to use are the complete backward incompatibility between versions and the requiring Scala to use templates.
Struts requires lots of classes and configurations for a single component, which can be cumbersome for many Java developers.
JSF offers a simple framework for creating reusable web components in your Java applications without a large learning curve. It doesn’t require extra downloads or configuration as the necessary code is bundled in any Java EE compliant application server. JSF’s tooling makes it easy to use and there are no external dependencies as long as you stay within the Java EE ecosystem, which JSF leverages well. There are also several built-in components that provide tremendous benefit and some third-party component libraries that look great.
4. Documentation and Community
A good framework needs excellent documentation so that new users can get started quickly, and an active community to support users of all tenures. In this section, we compare the documentation and community of each Java web framework.
Being the most used framework by Java developers definitely has its perks. Spring has a wealth of documentation, tutorials, and GitHub repositories. There are also numerous Spring User Groups and Java User Groups that discuss Spring topics.
Grails has an official manual, tutorials, screencasts, a sample app and more. If that isn’t enough, then look through 42k topics in the mailing list or search through nearly 12k grails-tagged questions on SO.
Documentation? How about a book that you can use to swat an elephant! The Book of Vaadin is a must have reference manual for all your queries. There’s also substantial documentation online, including tutorials and demo videos, which are extremely easy to learn from and replicate. The community is strong with an active forum, blog, webinars, conferences, etc.
GWT has surprisingly extensive official documentation. There are numerous FAQs, reference guides and overviews about pairing GWT with other frameworks. The site also has sections for books written about GWT itself and paired with other frameworks (namely Vaadin), case study videos, sample projects, and presentations given at various conferences. Developers can benefit GWT by getting involved in general discussions on the GWT group and by becoming a GWT Contributor.
The Wicket website hosts a large compilation of available examples, sample projects, and resource links. The examples provided range from your basic “Hello, World!” to examples detailing specific Wicket framework features, such as fragments and AJAX. Wicket set up an IRC for more direct support, there are a few dozen companies that provide commercial support, and there are a splattering of community meetups worldwide.
The Play framework site has full reference-level documentation and even covers secondary documentation that covers the non-framework pieces of Play, like Akka and SBT. The community is very active and there are several companies that base their main sites and applications on the Play framework. Bugs reports and feature requests are solicited from the community on a regular basis, which leads Play to have a robust and active community.
We’re not going to sugarcoat it: official Struts documentation is lacking, but user written tutorials help to fill in the gaps. The community is big enough, considering the age and popularity of the framework, so you won’t be let alone with your problem.
JSF is unlike any other framework listed here for one main reason: It is fully supported and has a reference implementation from Oracle. JSF has a top-down community with Oracle at the head paying employees to write documentation and create samples and examples. While the Java EE specification is determined by the Java Community Process (JCP), Oracle has a large part in determining and supporting features present in the specification. The only downside of the documentation from Oracle is the reliance of their IDE and Application Server. Requiring Netbeans and Glassfish is definitely a detriment to the documentation and tutorials.Back to top
Final Thoughts: The Results
Not all frameworks are created equal. In the same way that comparing WebLogic with Jetty doesn’t exactly make sense to some Java developers, some of you will surely find issue with comparing Spring MVC, which is part of a much larger framework ecosystem, to Vaadin or Struts. And in reality, you may choose to use a combination of frameworks rather than just one. There’s certainly no runaway winner, but a sizeable gap separates them from Wicket, Spring MVC and Struts.
Grails came out on top for 5 of the 8 categories, doing particularly well around the Rapid application development, documentation and community with top marks. Vaadin received top marks across the board, but particularly stood out with community and documentation. GWT wasn’t far behind, which is expected given how similar it is in functionality to Vaadin. JSF holds a specific place in the Java tech stack given its inclusion in Java EE, yet still performed solidly. The steep learning curve with Play kept it from ranking higher. Once you get used to Play you can create applications very quickly, but where it really excels is in the scalability and throughput.
No matter what Java web framework you’re using, you can save development time by eliminating rebuilds and redeploys with JRebel. See for yourself during your 14-day free trial.
This blog was originally published in July 2013 and has been edited for clarity.Back to top