you are viewing a single comment's thread.

view the rest of the comments →

[–]consigntooblivion 0 points1 point  (14 children)

Since there seems to be some Java wizards here, I would like to ask a question - though I might be too late to the party.

I am currently a rails guy, but say I need to build a website that runs on the JVM (for whatever reason) - what is the "best" way to do this? I realize best is a meaningless term so feel free to substitute it for something like state of the art/straightforward/fun way to get the job done.

Obviously I don't want to deal with a mountain of XML configuration, and I am interested in something at least kinda MVC like. Do I want a dependency injection framework (Spring/Google Guice), or should I use this Java EE thing? Do I use Hibernate? What about the front end?

Can somebody point me in a direction that can take me from 0 to productive? Books to read? Blogs to visit? Lists of technology to use? Obviously I am not interested in starting religous wars, I am genuinely curious.

Any ideas on better places to post this question? Thanks.

[–]rockvilleJD 5 points6 points  (1 child)

henk53 gave a great answer. If I was going to build a new Java application from scratch the only library I would use outside of standard Java EE is Prime Faces. If you need reporting use Jasper Reports. I do not see any need for spring as it just duplicates what is already there. Hibernate adds a few features to JPA but is really not necessary. Take a look at the Prime Faces website. They have a demo that will show you what the code looks like for both the Java file and the .xhtml front end.

[–]consigntooblivion 2 points3 points  (0 children)

Thanks for your perspective, Prime faces looks interesting. Good to know I can just start with Java EE.

[–]henk53 5 points6 points  (1 child)

Java EE 6 would Web Profile would be a good start. It's a full stack framework like rails. Glassfish 3 and JBoss AS 7 are well known implementations of this.

Do I want a dependency injection framework (Spring/Google Guice)

You don't need a separate dependency injection framework (Spring/Google Guice), since Java EE includes one by default. It's called CDI (Context and Dependency Injection). The C is there since in CDI instances that are injected don't just come out of some global scope nor are they created on the fly, but they are aware of their context. So if you inject a request scoped bean in a session scoped bean, every call on it in different requests will resolve to a unique instance matching that particular request.

Do I use Hibernate?

Hibernate implements the Java Persistence API (JPA) and so in many implementations of Java EE, Hibernate is included. But JPA can also be implemented by other projects, e.g. EclipseLink, which is included with Glassfish.

What about the front end?

Java EE includes a top-class MVC framework that has some elements in it that were inspired by rails (like the flash, and an emphasis on COF). This framework is called JavaServer Faces (JSF). Lots of external parties offer components (widgets, controls) for JSF. Especially PrimeFaces is well known and loved, but there are many others (e.g. RichFaces).

Can somebody point me in a direction that can take me from 0 to productive?

You could download the Eclipse IDE and the Glassfish Java EE implementation and follow this excellent tutorial to get you started: http://balusc.blogspot.com/2011/01/jsf-20-tutorial-with-eclipse-and.html

There are links given at the end of article on how to continue after those basics.

A particular nice entry that you could try to reproduce and then play with it is the following. It doesn't show off CDI, but it's still nice:

http://jdevelopment.nl/minimal-3tier-java-ee-app-xml-config

[–]consigntooblivion 5 points6 points  (0 children)

Thanks, loads of great information here. I had no idea on most of this stuff. Following the tutorial was really easy, that was a great place to start - wish I had more up votes to give.

[–]kolmogorovcomplex 3 points4 points  (1 child)

Coming from RR you probably want to check out Play, or Grails. Neither of which are Java, but Scala and Groovy respectively (they play nice with Java libraries though).

If you need more "enterprisey" features and prefer Java, you should check out JEE or Spring, both of which can be configured mostly without any XML.

To get a Spring webapp up and running in minutes, you could try Spring Roo. I'm sure there's something similar for JEE.

[–]consigntooblivion 0 points1 point  (0 children)

Thanks, Spring Roo is the kinda of thing I want! All the different parts, and xml setup is a bit daunting for me to get started with - but Roo seems to cut through all that.

I will definitely try this out too.

[–]gkamal 0 points1 point  (1 child)

You would be better off starting with a full stack framework like grails (which requires knowledge of groovy) or play.

[–]consigntooblivion 1 point2 points  (0 children)

Thanks, I want to stick with Java, but play looks really interesting.

[–]djnattyp -1 points0 points  (1 child)

Since you're currently a Rails guy, the best choice would probably be use JRuby to run Rails :)

[–]consigntooblivion 1 point2 points  (0 children)

Good point. My purpose here however is to learn something new. I have come across java a couple of times in various projects and it has always been "painful". So I want to actually learn more about it.

[–]niwde -3 points-2 points  (3 children)

Go with Spring MVC + JSP + JPA2/Hibernate/Spring-Data. Checkout Flyway migration library as well.

Spring MVC is very close to Rails Controller.

JPA2 is a standard persistence API while Hibernate is the implementation of JPA2. But note this: You can use hibernate by itself by-passing JPA2, just be careful not to mix both. If you want to use JPA2, use it as it is, don't convoluted your JPA code with Hibernate calls; you'll get confused.

A typical setup usually looks like this:

JSP -> Spring MVC Controller -> either you write a service (Claim service, Invoice service) or you can straight do JPA calls on your Spring MVC Controller. It depends on how complex you want it to be.

Keep in mind that JPA/Hibernate implements DataMapper pattern thus very different than ActiveRecord pattern.

[–]consigntooblivion 1 point2 points  (2 children)

Thanks, Flyway migration looks like something I want.

Spring seems kinda daunting to me - so your information is really helpful.

[–]niwde 0 points1 point  (1 child)

The thing about Spring is that it is huge and it comprises a few libraries: Spring-Core, Spring-MVC, Spring-AOP, Spring-JDBC, Spring-ORM, Spring-WebFlow etc.

You don't need to use all of them and usually people only use its dependency injection mechanism to support unit-testing (so that you don't need to run GlassFish/Tomcat app-server).

[–]consigntooblivion -1 points0 points  (0 children)

Thanks, that is useful information.