Java EE 6 Example Projects For Eclipse and Maven Users

Introduction

As a long-time Java programmer who uses Eclipse as my IDE, Maven as my build tool, and Spring libraries I've been looking for a comfortable way to learn Java EE 6. Most of the Oracle tutorials and book examples use NetBeans and GlassFish and really just show you how to use the NetBeans wizards. I happened to run across a post about how to migrate from Spring to Java EE 6. In the comments for that post I learned about some very good Java EE 6 examples that use Maven and can be easily imported and run from within Eclipse.

This post is not about whether a developer should migrate from Spring to Java EE 6 or how to do that. Rather the best thing I learned is how to access and setup in Eclipse numerous Maven examples of Java EE 6 technologies. Whether you are a long-time Spring guru or new to Java, it does seem a good idea to learn Java EE 6. Since I work in Eclipse and use Maven, the example projects make it easier for me to study, test, and run the applications in an environment I already know.

JBoss Application Server 7

To get started visit https://docs.jboss.org/author/display/AS71/Getting+Started+Developing+Applications+Guide where you will find good instructions on setting up your development environment so you can easily work with the example applications.

To run integration tests and run the applications, you should download and install the latest version of JBoss AS 7. Download it (it's not very large), un-archive the download and your ready to go with the JBoss application server. It starts up fast.

JBoss Eclipse Tools

If you're reading this article, I'm assuming you use Eclipse. Be sure to read and follow the directions on installing the JBoss Eclipse tools. One note if you already have the m2eclipse plugin installed you may need to remove it so that the JBoss Eclipse plugins can install a different m2eclipse version (I had to do that).

Once you have the JBoss Eclipse tools installed you are ready to use both the JBoss application server and the example projects. The Getting Started Guide has a section on how to setup Eclipse to run JBoss AS 7 from within Eclipse.

JBoss AS 7 Quick Start Projects

I downloaded the JBoss Java EE 6 Maven based example projects here: https://github.com/jbossas/quickstart. The Getting Started Developing Applications Guide provides good instructions on importing the Maven quick start examples into Eclipse.

Note there are many more quick start projects in the download then what is shown in the Getting Started Guide.

Clean Up The Examples

After importing the example projects into Eclipse you may need to do a bit of clean-up. I edited the project properties so that the JRE System Library was pointed at my workspace default (JDK 1.7.0). For some of the projects, if you want to run the tests without starting the JBoss application server yourself, you need to specify the location of jbossHome in the arquillian.xml file found in src/test/resources.

Testing Java EE 6 With JUnit

Another good technique I learned from these example projects is how to use Arquillian with Maven to setup/run unit and integration tests. There is much more information here: http://arquillian.org/guides/getting_started/.

Deploy Your Java EE 6 Applications To The Cloud

When you installed the JBoss Eclipse tools, you installed the JBoss OpenShift Express plugin. This plugin enables you to deploy your Java EE 6 applications to RedHat's OpenShift Platform as a Service. There are instructions on how to deploy your project from within Eclipse to OpenShift here: https://www.redhat.com/openshift/community/blogs/getting-started-with-the-openshift-eclipse-plug-in-for-java-applications-on-the-cloud

I was able to deploy the number guess quick start Java EE 6 project and you can view it here: http://numberquess-phillips1021.rhcloud.com. Note: I did need to update the OpenShift Express plugin in Eclipse by updating it using this JBoss Nightly update site: http://download.jboss.org/jbosstools/updates/nightly/core/trunk/.

Apache Tomcat Java EE 6 Web Profile Application Server

Apache also has an application server - named TomEE that supports the Java EE 6 web profile. The Java EE 6 web profile is a subset of Java EE 6 technologies focused on ones a web application needs (e.g. JSF 2, JPA 2, EJB 3, CDI, Servlet 3, JTA, bean validation).

At the TomEE website are numerous Maven based example projects that demonstrate how to use one or more Java EE 6 technologies with TomEE. The examples can be checked out from this public subversion repository: http://svn.apache.org/repos/asf/openejb/trunk/openejb/examples. So this is another resource Eclipse/Maven developers can use to learn Java EE 6.

Summary

My next step is to continue to work my way through Oracle's Java EE 6 tutorial but using the example projects I imported above and converting where needed Oracle's example's into Eclipse/Maven projects.

Again this isn't a plug for switching from Spring to Java EE 6. Rather, I wanted to let other developers know about a good resource for learning Java EE 6 if you are currently using Eclipse and Maven. Hopefully, if you are an Eclipse/Maven user you'll find the example projects and other information provided by JBoss helpful.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Hello Bruce, I have also used the JBoss quickstarts (maven-based Java EE6 examples) to migrate a few of Oracle's Java EE6 Tutorial examples to eclipse/maven. From what I remember it was fairly smooth. I have also published several videos lately showing off various aspects of Eclipse, EE6, Maven and JBoss.
http://docs.jboss.org/tools/movies/
Plus we are working on even more getting started/tutorial content for www.jboss.org/developer

Burr
@burrsutter
# Posted By Burr Sutter | 4/22/12 12:04 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1.002. Contact Blog Owner