I have recently begun learning Java EE 6 after doing Java SE for some years now (together with other languages). I have bought different books about Maven, EJB, JSF, Glassfish and so on (not read them all yet though), and I feel absolutely overwhelmed of the complexity of just making a project.
How would I start a project from "scratch" (Not copying a from an example in the book) in eclipse? I can choose from Dynamic Web project, Maven project, EJB project, EAR application etc. Which should I use if I want to make an application that has EJB/JPA and JSF inside (web application)?
I know about the Standard Maven Directory Layout and archetypes, however I do not know which to choose if this is the way to do it. Of course, I understand that there are many ways of doing it and it is dependent on what I will use it for, but I am learning Java EE 6 so I want to at least have some knowledge of how to set up a basic project as well.
I am also rather overwhelmed by the POM file. How do I know which dependencies I need just to get started with a web application? Or is this included in the correct archetype (if I find one?)
I am using Glassfish as application server, Eclipse, EJB, JPA and JSF. Currently learning from book examples only.
Well, a complete answer to your question would pretty much need an entire book on it's own, but here's some pointers.
The notion of Java EE applications represents any kind of Java application that uses one or more of the Java EE APIs implementation and needs a Java EE application server to run. Java APIs are those such: Servlet,JSP, EJB, JPA, etc. Implementations of these APIs are usually provided by the application Server (like Tomcat has servlet and JSP implementations, Glassfish has those as well plus EJB, etc). There are, let's say non-application server Java EE APIs implementations like Hibernate's implementation of JPA. So in short if you use some of these APIs implementations in your app and deploy it into some application server like Tomcat, Glassfish, JBoss AS, etc, you have a Java EE application.
I've told you all this because in reality, most of the project management tools (like Eclipse, Maven, etc) use these subdivisions like Web-Application, EJB Module, Dynamic Web Project etc, as a custom denomination that establishes the ball park of what set of Java EE APIs your application will use. I.E. a Web Application or Dynamic Web Project will more likely use Servlet and JSP APIs, an EJB Module will (duh) use the EJB APIs and so on. These are, as I said, ball park denominations. A Dynamic Web Application can use EJB or JPA as well, it's not like it's written in stone.
When you use either of these tools such as Eclipse or Maven, to start one of these above mentioned, denominated projects, such as a Dynamic Web Project in Elcipse or a Standard Web Application with Maven, that respective tool will add the common sense dependencies to your template project (like Servlet and JSP in this case), and then let you handle it from here.
The idea here is to understand each type of template of your chosen tool before you use it at the start of your project. Like if you decide to use Eclipse and start with a Dynamic Web Project, you should check out what exactly Eclipse asks of you and does when you do that (it will ask you for the location of a locally installed Java EE application server from where it will pull in such dependencies as a Servlet Implemnentation and a JSP implementation amongs others). Or if you chose Maven, and start a standard web project, you should check out what dependencies it adds to your project via the pom.xml file, what the basic functions of THAT pom.xml file are, etc. You should also check out how each of these tools deploys your application when you tell it to do that, does it use some hot deploy feature of your Java EE server, does it need credentials to access that server first etc.
My brief advice is to start with the very basic example: Install a Tomcat (version 7 is recommended), start Eclipse for Java EE Development, add that Tomcat installation to your Eclipse config, start a Dynamic Web project that uses that Tomcat as Application server, and just do some basic servlets and JSP pages, then use Eclipse to deploy that sucker to tomcat and run it. Then you can branch off to more advanced stuff, like doing the same thing with Maven, integrating a Maven project with Eclipse, adding some more Java EE Stuff (like a JPA Implenentation), etc etc.
http://blogs.oracle.com/arungupta/entry/web_app_development_using_java provides a complete explanation of how to create a Java EE 6 project using Eclipse and GlassFish.
Alternatively, you can also NetBeans to create a Java EE 6 project as explained at:
http://blogs.oracle.com/arungupta/entry/screencast_37_java_ee_6
I can choose from Dynamic Web project, Maven project, EJB project, EAR application etc. Which should I use if I want to make an application that has EJB/JPA and JSF inside (web application)?
Before EJB 3.1 spec it was not possible to deploy EJBs in war files, but now, you can. So for a quick prototype you can use a war file rather than an ear file if that's all you require and you are more familiar with it. Of course you can also deploy it in an .ear file.
I believe the Dynamic Web project in Eclipse generates a .war file that you can deploy in your AS.
If you are using Maven, you can also create your project with Maven beforehand, and then import using Maven (via M2Eclipse plugin). This works pretty well for me. Then, with the Glassfish Maven plugin, you can deploy your app to Glassfish via command line.
I am also rather overwhelmed by the POM file. How do I know which dependencies I need just to get started with a web application? Or is this included in the correct archetype (if I find one?)
You need the Java EE dependencies at least in a "provided" scope as the server will probably provide these for you. This way they will be available for you in compilation mode. For instance, the one for the JBoss Java EE 5 stack is as follows (not sure about the GlassFissh dependency, but the important stuff is not to include the library in your .ear / .war in order to avoid library conflicts):
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
<version>5.0-1</version>
<scope>provided</scope>
</dependency>
Added: As you said, this can be overwhelming at the start, I think this is a good resource on how to setup a Glassfish / Java EE project. Pick the bits you are interested on and good luck.
The first thing I'd ask you is why you're learning so many technologies. If your purpose is getting a job, in my experience, there's a trend in companies away from Java EE and towards simpler solutions. For example, application servers are overkill for most organizations and Tomcat (or another web server) with helper technologies like Spring and standalone JMS servers replacing full-featured and much more complex Java EE servers.
I think you'd be better served focusing on core concepts and simpler technologies as you get started and staying away from IDEs, complex builds, EARs, etc. Instead, start with one or two technologies (e.g. a hello Tomcat app with a simple Ant build) and gradually add each technology in as you find the need. Better yet if you have a real world problem to solve, even if it doesn't pay.
Most companies (at least those with a technical clue) would rather hire a programmer who understands what value a technology like JSF adds and at what cost of complexity than someone with a lot of acronyms on their resume.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With