Can anyone recommend a simple Java web-app framework? [closed]
Asked Answered
A

33

65

I'm trying to get started on what I'm hoping will be a relatively quick web application in Java, yet most of the frameworks I've tried (Apache Wicket, Liftweb) require so much set-up, configuration, and trying to wrap my head around Maven while getting the whole thing to play nice with Eclipse, that I spent the whole weekend just trying to get to the point where I write my first line of code!

Can anyone recommend a simple Java webapp framework that doesn't involve Maven, hideously complicated directory structures, or countless XML files that must be manually edited?

Allahabad answered 22/9, 2008 at 19:31 Comment(0)
J
50

Haven't tried it myself, but I think

http://www.playframework.org/

has a lot of potential...

coming from php and classic asp, it's the first java web framework that sounds promising to me....

Edit by original question asker - 2011-06-09

Just wanted to provide an update.

I went with Play and it was exactly what I asked for. It requires very little configuration, and just works out of the box. It is unusual in that it eschews some common Java best-practices in favor of keeping things as simple as possible.

In particular, it makes heavy use of static methods, and even does some introspection on the names of variables passed to methods, something not supported by the Java reflection API.

Play's attitude is that its first goal is being a useful web framework, and sticking to common Java best-practices and idioms is secondary to that. This approach makes sense to me, but Java purists may not like it, and would be better-off with Apache Wicket.

In summary, if you want to build a web-app with convenience and simplicity comparable to a framework like Ruby on Rails, but in Java and with the benefit of Java's tooling (eg. Eclipse), then Play Framework is a great choice.

Jacobian answered 22/9, 2008 at 19:31 Comment(2)
Play framework hard to learn and brakes the JEE. It try to create its own eco system, stay away from it.Dorsoventral
Try debugging Play 2.0 framework code. If you don't know Scala you will have hard times with it.Solubilize
C
48

(Updated for Spring 3.0)

I go with Spring MVC as well.

You need to download Spring from here

To configure your web-app to use Spring add the following servlet to your web.xml

<web-app>
    <servlet>
        <servlet-name>spring-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring-dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

You then need to create your Spring config file /WEB-INF/spring-dispatcher-servlet.xml

Your first version of this file can be as simple as:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
        http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/mvc     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   <context:component-scan base-package="com.acme.foo" />    
   <mvc:annotation-driven />

</beans>

Spring will then automatically detect classes annotated with @Controller

A simple controller is then:

package com.acme.foo;

import java.util.logging.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/person")
public class PersonController {

    Logger logger = Logger.getAnonymousLogger();

    @RequestMapping(method = RequestMethod.GET)
    public String setupForm(ModelMap model) {
        model.addAttribute("person", new Person());
        return "details.jsp";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String processForm(@ModelAttribute("person") Person person) {
        logger.info(person.getId());
        logger.info(person.getName());
        logger.info(person.getSurname());
        return "success.jsp";
   }
}

And the details.jsp

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<form:form commandName="person">
<table>
    <tr>
        <td>Id:</td>
        <td><form:input path="id" /></td>
    </tr>
    <tr>
        <td>Name:</td>
        <td><form:input path="name" /></td>
    </tr>
    <tr>
        <td>Surname:</td>
        <td><form:input path="surname" /></td>
    </tr>
    <tr>
        <td colspan="2"><input type="submit" value="Save Changes" /></td>
    </tr>
</table>
</form:form>

This is just the tip of the iceberg with regards to what Spring can do...

Hope this helps.

Clarify answered 22/9, 2008 at 19:31 Comment(3)
Spring is surely a good and wide-spread framework, but it was asked for a simple Java webapp framework. ;-)Cardew
Where should details.jsp go? I've set this up as described and receive: 2012-09-24 21:57:31.236:WARN:oejs.ServletHandler:/details.jsp java.lang.NullPointerException at java.net.URLEncoder.encode(URLEncoder.java:205) ...Inandin
This is exactly the problem the original poster wanted to avoid. The need to write acres of this XML here, that XML there, lots of boilerplate code, making simple tasks complex, and complex tasks impossible. Should not it be the other way around?Edmee
M
28

I am really grooving to Stripes. Total setup includes some cut-and-paste XML into your app's web.xml, and then you're off. No configuration is required, since Stripes is a convention-over-configuration framework. Overriding the default behavior is accomplished via Java 1.5 annotations. Documentation is great. I spent about 1-2 hours reading the tutorial and setting up my first app.

I can't do an in-depth comparison to Struts or Spring-MVC yet, since I haven't built a full-scale in it yet (as I have in Struts), but it looks like it would scale to that level of architecture quite well.

Macdougall answered 22/9, 2008 at 19:31 Comment(1)
stripesframework.org/display/stripes/Stripes+vs.+StrutsArbitrament
Z
20

Your're searching for http://grails.org/

You code it with groovy, a dynamic language based upon Java and runs smoothly together with Java code, classes and libraries. The syntax is neither hard to learn nor far away from Java. Give it a try, it's some minutes to get a web site up and running. Just follow http://grails.org/Installation and http://grails.org/Quick+Start

Greetz, GHad

Zak answered 22/9, 2008 at 19:31 Comment(5)
Thanks, but I really want a Java framework, or Scala at a stretch. I need something with a minimal learning curve, and having to learn a whole new language, regardless of how simple it might be, isn't what I had in mind.Allahabad
Groovy really is so similar to Java that you can be writing what is effectively Java syntax and then as you grow more confident make it more Groovy. Grails really is a great framework for rapid prototyping of sites.Levulose
FWIW, you can write groovy code in Java- it'll compile it just fine.Lukash
and vice versa you can write java code in groovy. groovy is like java++.Caskey
@sanity, Groovy is much much closer to Java than Scala is. Grails is also built off Spring and Hibernate which is the defacto standard for Java enterprise applications because it is rock-solid.Guidry
A
8

Check out WaveMaker for building a quick, simple webapp. They have a browser based drag-and-drop designer for Dojo/JavaScript widgets, and the backend is 100% Java.

Andes answered 22/9, 2008 at 19:31 Comment(0)
D
7

Stripes : pretty good. a book on this has come out from pragmatic programmers : http://www.pragprog.com/titles/fdstr/stripes. No XML. Requires java 1.5 or later.

tapestry : have tried an old version 3.x. I'm told that the current version 5.x is in Beta and pretty good.

Stripes should be the better in terms of taking care of maven, no xml and wrapping your head around fast.

BR,
~A

Dancer answered 22/9, 2008 at 19:31 Comment(0)
S
6

Grails is written for Groovy, not Java. AppFuse merely reduces the setup time required to get any number of Webapp frameworks started, rather than promoting any one of them.

I'd suggest Spring MVC. After following the well-written tutorials, you'll have a simple, easy model auto-wired (with no XML configuration!) into any view technology you like.

Want to add a "delete" action to your list of customers? Just add a method named "delete" to your customer controller, and it's autowired to the URL /customers/delete.

Need to bind your request parameters onto an object? Just add an instance of the target object to your method, and Spring MVC will use reflection to bind your parameters, making writing your logic as easy as if the client passed a strongly-typed object to begin with.

Sick of all the forced MVC division of labor? Just have your method return void, and write your response directly to the servlet's Writer, if that's your thing.

Shortlived answered 22/9, 2008 at 19:31 Comment(0)
K
5

Have a look at Ninja Web Framework.

It is a pure Java MVC framework in the tradition of Rails. It does not use any xml based configuration and has all you need to get started right away: Session management, Security management, html rendering, json rendering and parsing, xml rendering and parsing. It also features a built-in testing environment and is 100% compatible with traditional servlet containers.

It uses Maven, though - but Maven used correctly makes software development super simple. It also allows you to use any Ide right away :)

By the way - developing Ninja is really productive - make changes to your code and see the results immediately.

Check out: http://www.ninjaframework.org.

Karlene answered 22/9, 2008 at 19:31 Comment(1)
It reminds me of rails. Beautiful. But no book or other detailed reference.Urbani
S
5

Apache Wicket, Liftweb) require so much set-up, configuration

I disagree, I use Wicket for all my projects and never looked back! it doesn't take much to set up, not even an hour to set up a full environment to work with Wicket..

Shanaeshanahan answered 22/9, 2008 at 19:31 Comment(4)
Agreed, I just started using it a couple days ago and got my environment up and running in less than an Hour (Wicket + Wicket-Spring + Hibernate). I'm in love.Tingey
...until you come to some extraordinary stuff. Wicket is not really simple.Impropriate
An hour is a long time. Play Framework requires about 2 minutes.Allahabad
... until you need to scale your application to more than one server or more than a handful of users. Then Wicket is no longer your friend.Sabella
A
5

The Stripes Framework is an excellent framework. The only configuration involved is pasting a few lines in your web.xml.

It's a very straight forward request based Java web framework.

Arbitrament answered 22/9, 2008 at 19:31 Comment(0)
R
5

I like Spring MVC, using 2.5 features there is very little XML involved.

Ramberg answered 22/9, 2008 at 19:31 Comment(0)
S
4

I like writing plain old servlets+winstone servlet container. From there I bolt on templating (velocity, XSLT, etc) and DB access (hibernate, torque, etc) libraries as I need them rather than going in for an actual framework.

Spaniard answered 22/9, 2008 at 19:31 Comment(1)
Minimal Java "framework" with Velocity + Play-style URI mapping: Drumlin.Venial
V
3

Try Apache Click

It is like Wicket, but much more productive and easy to learn.

Vengeful answered 22/9, 2008 at 19:31 Comment(1)
The main reason for using Click is that it's among the few frameworks I understand how it works (not really, but at least at a degree to feel comfortable with it).Giannini
I
2

You can give JRapid a try. Using Domain Driven Design you define your application and it generates the full stack for your web app. It uses known open source frameworks and generates a very nice and ready to use UI.

Impropriate answered 22/9, 2008 at 19:31 Comment(0)
A
2

Grails is the way to go if you like to do the CRUD easily and create a quick prototype application, plays nice with Eclipse as well. Follow the 'Build your first Grails application' tutorial here http://grails.org/Tutorials and you can be up and running your own application in less than an hour.

Antagonize answered 22/9, 2008 at 19:31 Comment(0)
A
2

The web4j tool markets itself as simple and easy. Some points about it:

  • uses a single xml file (the web.xml file required by all servlets)
  • no dependency on Maven (or any other 3rd party tool/jar)
  • full stack, open source (BSD)
  • smallest number of classes of any full stack java framework
  • SQL placed in plain text files
  • encourages use of immutable objects
  • minimal toolset required (JSP/JSTL, Java, SQL)
Anima answered 22/9, 2008 at 19:31 Comment(0)
M
2

After many painful experiences with Struts, Tapestry 3/4, JSF, JBoss Seam, GWT I will stick with Wicket for now. Wicket Bench for Eclipse is handy but not 100% complete, still useful though. MyEclipse plugin for deploying to Tomcat is ace. No Maven just deploy once, changes are automatically copied to Tomcat. Magic.

My suggestion: Wicket 1.4, MyEclipse, Subclipse, Wicket Bench, Tomcat 6. It will take an hour or so to setup but most of that will be downloading tomcat and the Eclipse plugins.

Hint: Don't use the Wicket Bench libs, manually install Wicket 1.4 libs into project.

This site took me about 2 hours to write http://ratearear.co.uk - don't go there from work!! And this one is about 3 days work http://tnwdb.com

Good luck. Tim

Missis answered 22/9, 2008 at 19:31 Comment(0)
W
2

The correct answer IMO depends on two things: 1. What is the purpose of the web application you want to write? You only told us that you want to write it fast, but not what you are actually trying to do. Eg. does it need a database? Is it some sort of business app (hint: maybe search for "scaffolding")? ..or a game? ..or are you just experimenting with sthg? 2. What frameworks are you most familiar with right now? What often takes most time is reading docs and figuring out how things (really) work. If you want it done quickly, stick to things you already know well.

Willhite answered 22/9, 2008 at 19:31 Comment(0)
C
2

I really don't see what is the big deal with getting maven + eclipse to work, as long as you don't have to change the pom.xml too much :)

Most frameworks that user maven have maven archetypes that can generate stub project.

So basically the steps should be:

  1. Install maven
  2. Add M2_REPO class path variable to eclipse
  3. Generate project with the archetype
  4. Import project to eclipse

As for Wicket, there is no reason why you couldn't use it without maven. The nice thing about maven is that it takes care of all the dependencies so you don't have to. On the other hand, if the only thing you want to do is to prototype couple of pages than Wicket can be overkill. But, should your application grow, eventually, the benefits of Wicket would keep showing with each added form, link or page :)

Charterhouse answered 22/9, 2008 at 19:31 Comment(0)
A
2

Tapestry 5 can be setup very quickly using maven archetypes. See the Tapestry 5 tutorial: http://tapestry.apache.org/tapestry5/tutorial1/

Archduchy answered 22/9, 2008 at 19:31 Comment(0)
C
1

I would think to stick with JSP, servlets and JSTL After more than 12 years dealing with web frameworks in several companies I worked with, I always find my self go back to good old JSP. Yes there are some things you need to write yourself that some frameworks do automatically. But if you approach it correctly, and build some basic utils on top of your servlets, it gives the best flexibility and you can do what ever you want easily. I did not find real advantages to write in any of the frameworks. And I keep looking.

Looking at all the answers above also means that there is no real one framework that is good and rules.

Cusec answered 22/9, 2008 at 19:31 Comment(0)
C
1

Also take a look at activeweb. its simple, lightweight and makes use of a few other things that i like (guice, maven...). Its controllers can serve anything you want including json, Html, plain text, pdfs, images... You can make restful controllers and even use annotations to determine which http methods(POST, GET, ...) a controller method accepts.

Crouse answered 22/9, 2008 at 19:31 Comment(0)
M
1

I found a really light weight Java web framework the other day.

It's called Jodd and gives you many of the basics you'd expect from Spring, but in a really light package that's <1MB.

http://jodd.org/

Marrs answered 22/9, 2008 at 19:31 Comment(2)
It's not only a web framework; there is ioc container, aop engine, db mapping engine, html processing tools (decorator, minifier...) etc.Hutt
Jodd is very impressive indeedMarrs
A
1

try Vaadin! Very simple and you'll be able to work the UI with ease as well! www.vaadin.com

Agnostic answered 22/9, 2008 at 19:31 Comment(1)
As GWT is as good as dead, this would not be recommended.Stonewort
H
1

Castleframework

http://maven.castleframework.org/nexus/content/repositories/releases/

install using maven.

Hochstetler answered 22/9, 2008 at 19:31 Comment(0)
N
1

try Wavemaker http://wavemaker.com Free, easy to use. The learning curve to build great-looking Java applications with WaveMaker isjust a few weeks!

Nielson answered 22/9, 2008 at 19:31 Comment(1)
This is very subjective, but I found the Wavemaker widgets really ugly :-)Edmee
L
1

I haven't used it by AppFuse is designed to facilitate the nasty setup that comes with Java Web Development.

Ligetti answered 22/9, 2008 at 19:31 Comment(0)
D
0

A common property of Java Web-apps is that they usually use servlets which usually means the web server also runs Java. This contributes to the perceived complexity, IMHO. But you can build Java apps in the traditional Unix-style of "do one thing and do it well" without having performance suffer.

You can also use SCGI, it is a lot simpler than FastCGI. I'd try that first. But if it doesn't work out:

How to write a FastCGI application in Java

  1. Make an empty working directory and enter it
  2. Download the FastCGI devkit: wget --quiet --recursive --no-parent --accept=java --no-directories --no-host-directories "http://www.fastcgi.com/devkit/java/"
  3. mkdir -p com/fastcgi
  4. mv *.java com/fastcgi
  5. Now you need to apply a tiny patch to the devkit (replace operator == with <= on line 175 or use this script to do it):

    echo -e "175c\nif (count <= 0) {\n.\nw\nn\nq" | ed -s com/fastcgi/FCGIInputStream.java

  6. Create a test app, TinyFCGI.java (source below)
  7. Compile everything: javac **/*.java (** will probably only work in zsh)
  8. Start the FastCGI server: java -DFCGI_PORT=9884 TinyFCGI (leave it running in the background)
  9. Now set up e.g. Apache to use the server:

    • Using Apache 2.4, you can use mod_proxy_fcgi like this:
      1. Using Ubuntu, upgrade to Apache 2.4 using i.e. this PPA
      2. Enable the mod: sudo a2enmod proxy_fcgi
      3. Create /etc/apache2/conf-enabled/your_site.conf with the content below
      4. Restart Apache: sudo apache2ctl restart
  10. Now you can access the webapp at http://localhost/your_site

  11. Benchmark results below

TinyFCGI.java

import com.fastcgi.FCGIInterface;
import java.io.*;
import static java.lang.System.out;

class TinyFCGI {
    public static void main (String args[]) {
        int count = 0;
        FCGIInterface fcgiinterface = new FCGIInterface();
        while(fcgiinterface.FCGIaccept() >= 0) {
            count++;
            out.println("Content-type: text/html\n\n");
            out.println("<html>");
            out.println(
                "<head><TITLE>FastCGI-Hello Java stdio</TITLE></head>");
            out.println("<body>");
            out.println("<H3>FastCGI-HelloJava stdio</H3>");
            out.println("request number " + count +
                               " running on host "
                               + System.getProperty("SERVER_NAME"));
            out.println("</body>");
            out.println("</html>");
        }
    }
}

your_site.conf

<Location /your_site>
  ProxyPass fcgi://localhost:9884/
</Location>

Benchmark results

wrk

$ ./wrk -t1 -c100 -r10000 http://localhost/your_site 
Making 10000 requests to http://localhost/your_site
  1 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.58s    13.42s    1.06m    94.42%
    Req/Sec     0.00      0.00     0.00    100.00%
  10000 requests in 1.42m, 3.23MB read
  Socket errors: connect 0, read 861, write 0, timeout 2763
  Non-2xx or 3xx responses: 71
Requests/sec:    117.03
Transfer/sec:     38.70KB

ab

$ ab -n 10000 -c 100 localhost:8800/your_site
Concurrency Level:      100
Time taken for tests:   12.640 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      3180000 bytes
HTML transferred:       1640000 bytes
Requests per second:    791.11 [#/sec] (mean)
Time per request:       126.404 [ms] (mean)
Time per request:       1.264 [ms] (mean, across all concurrent requests)
Transfer rate:          245.68 [Kbytes/sec] received

siege

$ siege -r 10000 -c 100 "http://localhost:8800/your_site"
** SIEGE 2.70
** Preparing 100 concurrent users for battle.
The server is now under siege...^C
Lifting the server siege...      done.
Transactions:              89547 hits
Availability:             100.00 %
Elapsed time:             447.93 secs
Data transferred:          11.97 MB
Response time:              0.00 secs
Transaction rate:         199.91 trans/sec
Throughput:             0.03 MB/sec
Concurrency:                0.56
Successful transactions:       89547
Failed transactions:               0
Longest transaction:            0.08
Shortest transaction:           0.00
Destalinization answered 22/9, 2008 at 19:31 Comment(0)
N
0

Try this: http://skingston.com/SKWeb

It could do with some more features and improvements, but it is simple and it works.

Numen answered 22/9, 2008 at 19:31 Comment(1)
It's been taken offline now, not convenient.Euphemism
D
0

I recommend Apache Click as well. If you pass the test of ten minutes(I think that's the time you will take to read the Quick Start Guide) you won't come back!

Regards,

Gilberto

Dimorphous answered 22/9, 2008 at 19:31 Comment(0)
C
0

Recently i found the AribaWeb Framework which looks very promising. It offers good functionality (even AJAX), good documentation. written in Groovy/Java and even includes a Tomcat-Server. Trying to get into Spring really made me mad.

Cardew answered 22/9, 2008 at 19:31 Comment(0)
R
0

Oracle ADF http://www.oracle.com/technology/products/jdev/index.html

Rhinology answered 22/9, 2008 at 19:31 Comment(0)
L
0

Have you tried DWR? http://directwebremoting.org

Lukas answered 22/9, 2008 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.