Simple Java web framework
JavaWeb FrameworksJava Problem Overview
Is there any simple java web framework like sinatra (for ruby) or web.py (for python)?
Java Solutions
Solution 1 - Java
If you want a strict Java framework Spark might be an alternative:
import static spark.Spark.*;
public class HelloWorld {
public static void main(String[] args) {
get("/hello", (req, res) -> "Hello World");
}
}
Solution 2 - Java
Play. Haven't tried it myself but heard only good things about it and seems to be quite beginner-friendly.
Solution 3 - Java
I think the simplest thing to do to generate web content via Java is to write a Servlet. Just like web.py allows you to define a GET
method, you can implement a Servlet's doGet()
method and write data directly back to the client.
Here is a link to the Servlets tutorial. You will also need to know how to package and deploy a web application; for that I usually point people to the Tomcat manual (see the section titled "First Web Application").
Writing and deploying a Java web application is not going to be as fast as in Ruby or Python, but Java isn't particularly known for its succinctness.
If you don't strictly require Java, check out Grails. It's a web application framework built on Groovy, which is a dynamic language similar to Python and Ruby that compiles to the JVM.
Solution 4 - Java
Java EE 6 Servers like GlassFish bundles it by default.
If you use Tomcat, you can use Jersey, Apache CXF, or Restlet implementations.
Using JAX-RS annotations the web development feels like Sinatra or Merb. BTW you don't have to use Java as the language, you can use Scala, Groovy, JRuby...
Solution 5 - Java
If you are only looking for a presentation framework in pure Java then, for me, Stripes1 is the closest of the Java MVC frameworks to the RoR philosophy: simple, elegant, and requiring minimal configuration.
1 Stripes pioneered the Convention over Configuration approach for Java web development. And while some other frameworks have adopted some of its principles (like Spring MVC or Struts2 with plugins), I still prefer Stripes because it does one thing, and does it well.
Solution 6 - Java
Solution 7 - Java
look at this two as well: 1. activeweb and 2. dropwizard
Solution 8 - Java
Check SerfJ : Simplest Ever Rest Framework for Java :
> Using SerfJ is the easiest way of developing Java REST web > applications. It helps you to develop your application over an elegant > MVC arquitecture, giving more importance to convention than > configuration, so for example, you will not have to have configuration > files or annotations in order to specify which view serves a > controller's method. However, SerfJ is very flexible library, so if > you want to jump over those conventions, you can configure the > behaviour of your applications as you like. > > The framework tries to meet JSR 311 specification, but it doesn't > follow every point of that, because the purpose is to have a very > intuitive library, and some some aspects of the specification are out > of the scope of SerfJ. > > SerfJ is opensource and is released under the Apache License, Version > 2.0.
Solution 9 - Java
You might want to have a look at those 2 groovy projects:
https://github.com/webdevwilson/graffiti
https://github.com/bleedingwolf/Ratpack
Really light akin to Sinatra. Might be a bit on the bleeding edge though:-) Interesting and promising never the less.
Solution 10 - Java
If you have to develop business or database applications http://www.openxava.org">OpenXava</a> is a good option. OpenXava allows you to develop a complete AJAX web application writing just domain classes, with no code generation and producing an application ready for production. Little code, great result.
Solution 11 - Java
The smallest "usable" web server for Java that support Servlets that I can find is Miniature JWS. And honestly there is no reason to run a Java web server that doesn't support Servlets. If you want to do REST, Restlet has a built in HTTP daemon that means you can run it as a stand alone web server.
Solution 12 - Java
HybridJava framework is really simple. Of course, it builds like an API above Servlet API, but deals with page and component instead of request and response. In other words it is truly MVC.
Solution 13 - Java
Step is a framework for Scala inspired by Sinatra.
Solution 14 - Java
I can recommend Struts2 to you, because i like the plugin architecture and with the convention plugin it is simple and fast to develop.