

Ask HN: Java FUD - swah

I want to use Jersey (JAX-RS) to write a web app in the static files+AJAX fashion. I also want to use Java because otherwise I can always keep blaming tools and documentation for things not working out.<p>So I go over to Java land, and the feeling is that I need to, to get things running, get to know about Tomcat, Hibernate, Maven and JBoss just to get started.<p>Now, having used Python+Django, I use to favor simpler solutions over complex ones.<p>What do you advise me to do? Is this just FUD? Should I try a non-EE Java solution (Lightweight java?), or just embrace the 3-letter acronyms?
======
mgkimsal
Use Grails - <http://grails.org>.

You will need to know Java/Groovy. Groovy can be considered a superset of Java
(not 100% technically true, but easy enough to think of that way to get
started).

> grails run-app

will run grails in dev mode on its own tomcat.

> grails prod run-app

will run grails in production mode on its own tomcat.

You can proxy Apache on port 80 to the tomcat port (default 8080).

Grails uses Hibernate under the hood, but hides it pretty darn well - you
generally won't need to know much about it, or even touch any XML config files
- to get started.

You can slowly add more Java libraries as required.

<http://www.grails.org/plugin/jaxrs> \- this is a JAX-RS plugin for Grails
which lets you use Jersey as the implementation if you want to ("At the
moment, plugin users may choose between Jersey and Restlet as JAX-RS
implementations").

The "Play!" framework might be interesting to you too, if you already know
some Java, but I prefer Grails overall.

~~~
HowardRoark
I second that Grails advice. Jersey, Hibernate and Maven isn't that bad, but
Grails beats that anyday if you don't mind Groovy. While Play framework is
cool too if you want to stick with Java, but it is not as mature as Grails or
any other Java frameworks.

~~~
mgkimsal
I was going to go in to a bit more detail, and this might be the place.

All your own code in Grails can be 'plain Java' if you want (or pretty darn
close to it). The nice thing is the Java people who want to stick with Java
_can_ do that in Grails, or you can go pretty deep in to Groovy if you want.

Grails uses Maven and Hibernate, but you don't need to become masters in them
before you start being productive.

This is why I like Grails so much - I've been able to be productive from a
very early stage. The more I learn about the under the hood tools, the more
productive I become, but I didn't need to understand or configure Hibernate,
Sitemesh, Maven or Tomcat to get going. Now that I know more about them, it's
even better, but it's great to jump in and have a working app early on (even
if it's pretty basic).

Perhaps others learn differently, but Grails has been a great 'on ramp' to
Java for me.

~~~
kls
Well if you are going to jump out of Java then Scala should be a consideration
as well. Even the Groovy creator commented that had Scala existed he would
probably not have created Groovy. Wit Scala you can still use JAX-RS.

[http://www.yes-no-cancel.co.uk/2009/05/13/building-go-
test-i...](http://www.yes-no-cancel.co.uk/2009/05/13/building-go-test-it-fun-
with-scala-and-rest-apis/)

~~~
mgkimsal
Well Scala _existed_ at that time (2003), but that's not what he'd said. If
someone had showed him a 2008 book on Scala in 2003, he'd have not created
Groovy.

All that said, Strachan isn't really involved in Groovy and hasn't been for
many years, so I'm not sure his views on the language or its appropriateness
is of that much concern. A whole new team of people have been running with
Groovy for years, and continue to make it better and more useful to people.

Scala is different enough from Java that syntactically that it's a hard sell
for many. Groovy is far more Java-ish for Java devs to pick up, and as such I
think it will continue to have a growing userbase for the foreseeable future
(but I'm biased, as I run groovymag.com!)

~~~
kls
Yeah, after re-reading my comment it comes off a lot more rude than was my
intention. The point was to say that Scala is a really nice modernized "Java"
(I know it is not but for simplicity, that is what I am going to call it) and
that even the creator of Groovy thinks it has one of the most elegant designs
out of the pack of Java replacements.

~~~
mgkimsal
NP - I didn't take it as rude. Just wrong ;)

~~~
kls
I don't see how recommending looking at Scala can be factually right or wrong,
your bias may be influencing your bering there. The elegance of a language is
subjective. The fact that Grooves founder finds it elegant lends credence to
the fact that it is a popular opinion. Still no more right or wrong.

~~~
mgkimsal
The ;) is a wink - was meant to indicate to take it lightheartedly (aka a
joke).

------
cscotta
Hey Hugo,

I've somehow become a bit of a devil's advocate for Java lately. Thanks for
pinging me - happy to offer a few thoughts.

I've not actually tried using Jersey/JAX, but it looks like a very clean setup
for quickly writing low-latency JSON APIs. I'm impressed by the Getting
Started example (here: <https://jersey.dev.java.net/use/getting-started.html>)
and find the use of decorators to specify path, methods, and content types
creative.

As for the rest, keep in mind that you don't have to use anything that you
don't want to. I've done a fair amount of Java development and never actually
used Hibernate, Maven, or JBoss. For the most part, the complexity that these
tools can introduce, while great for many projects, kind of scares the crap
out of me. Like you, I'd always go for the simplest workable solution
available.

Jetty is a very nice, simple alternative to Tomcat/JBoss, though I find Tomcat
to be rather nice myself. One thing I've come to love about Java deployment is
that you're literally deploying just one file (a .jar or .war) rather than
hundreds.

If you're looking for a nice, clean ORM, check out ActiveObjects by
@djspiewak. Its design is based on the active record pattern, and it's very
easy to get up and running with about any database as a backend. I used this
on a large project ending a few months ago and had a great experience with it.
Daniel's also available via Twitter and IRC and tends to be happy to offer an
answer to a quick, informed question. Here's the post he introduced it with
(<http://www.codecommit.com/blog/java/an-easier-java-orm>), and here's the
project page. (<https://activeobjects.dev.java.net/>). I'd also strongly
recommend checking out these docs he put together:
<https://activeobjects.dev.java.net/ActiveObjects.pdf>

I really love the "static files + AJAX" approach that you've suggested (it's
actually the same one mentioned in the project I referred to above). If you
were to build something with Jersey and ActiveObjects, perhaps with a small
caching layer in between (either an in-app cache if you'll only have one app
server, or memcached), you will have produced a screaming API for your
application.

The Play framework (mentioned below) is also very good, and has emerging
support for Scala, which I and many others find to be much cleaner and more
expressive than the equivalent Java. If you're feeling adventurous, I whipped
together a quick little framework for building zippy JSON APIs and simple
frontends via a lightweight wrapper around the servlet API. It's called Miso.
Here's the info on that (and do ping me if you feel like playing with this - I
may have a more recent version):
[<http://blog.paradoxica.net/post/401365886/hello-miso>]. See here for docs,
and especially page 6, which shows what a sample controller / API endpoint
looks like: <http://u.phoreo.com/gx.pdf>

Of course, this also depends on whether you actually need that, and how much
experience (or desire to learn) you have. If you're comfortable with Python,
something like Flask or Piston might be more appropriate. At the same time, I
would suggest that those who say that '"x language" or "y framework" makes
developers infinitely more productive' aren't offering terribly productive
advice, as I find myself about equally productive in Java, Scala, Python, and
Ruby, and often opt for Scala or Java unless I'm hammering out something quick
and imprecise. That is to say, it's definitely a matter of preference. So,
choose what you think will make you most productive, or, choose to learn
something new which might be a bit difficult at first, but will also teach you
a lot about statically-typed languages and could potentially meet the needs of
your application with far fewer resources and lower latency on the server-side
for years to come.

Regardless of which path you choose, feel free to hit me up with any questions
along the way.

~~~
kls
_I've not actually tried using Jersey/JAX, but it looks like a very clean
setup for quickly writing low-latency JSON APIs._

I was a very early adopter of Jersey and JAX-RS and I have to say, it is one
of the first API's that I have seen come out of Java that provides the rapid
development and prototyping typical of Ruby or Python. If future Java API's
take their queue from JAX-RS then Java will again become competitive. I
trained a guy just last week on JAX-RS and had him up and running in less that
a day. Only truly elegant designs can provide that level of simplicity while
exposing the ability to accomplish the task you want without having to make
compromises. JAX-RS is a gem in the Java world and I hope that future Java
API's will follow suite.

As well Netbeans tooling for JAX-RS goes a long way to reduce development
time. You can write a JPA annotated class and Netbeans will gen the schema as
well as the REST service. Or you can write the schema and Netbeans will gen
the JPA class and the service. While I am generally not a fan of reliance on
tooling this is a case where it helps without pooping all over your code.

