Category Archives: Web Development

Developing Java EE 6 Applications With TomEE and NetBeans

I’ve found that one of the most productive ways of developing Java EE applications is by using NetBeans and the TomEE application server.  For those of you that haven’t used TomEE before, it’s a Java EE 6 Web Profile certified stack that sits on top of Apache Tomcat.

As TomEE is Java EE 6 web profile certified, it supports the following technologies (all via Apache products) out of the box:

  • CDI
  • EJB
  • JPA
  • JSF
  • JSP
  • JSTL
  • JTA
  • Servlet
  • Javamail
  • Bean Validation

If you want / need to use JMS or JAX-RS/WS, then there’s an additional distribution called TomEE+ that provides support for these features.

I prefer to use Maven for project management / builds / testing etc which integrates well with NetBeans.

Using NetBeans, you can easily create a TomEE compatible Maven project by creating a new Maven Project from Archetype within the NetBeans New Project wizard.

Maven

The “tomee-webapp-archetype” will create a basic Web Application that’s defined and ready to deploy against TomEE.

Within the generated pom.xml file, we can see the important TomEE specific aspects are the use of OpenEJB for the EE api’s

<dependency>
      <groupId>org.apache.openejb</groupId>
      <artifactId>javaee-api</artifactId>
      <version>6.0-4</version>
      <scope>provided</scope>
</dependency>

and the use of the TomEE Maven plugin

<plugin>
        <groupId>org.apache.openejb.maven</groupId>
        <artifactId>tomee-maven-plugin</artifactId>
        <version>1.0.1</version>
</plugin>

Using the TomEE Maven plugin allows the project to be built and deployed to TomEE (without having to download TomEE!). This is useful for building and compiling from the command line. To get Maven to download TomEE, deploy your project to it and then start TomEE up, use the command

mvn tomee:run

Having said that, I prefer to use NetBeans to control running my projects as this provides more advanced features such as hot deployment of JSP/JSF, controlled execution of tests etc.

To run the project from within NetBeans, simply open up the pom.xml from the File | Open Project wizard in NetBeans. NetBeans is clever enough to open Maven projects which then function just like a standard NetBeans project. Select the “Run” option and NetBeans will ask which application server to run the application on. The is no direct support for TomEE, (i.e. you don’t see an Application Server of type TomEE in the NetBeans server configuration page) but since TomEE is based on Tomcat, to define a TomEE server, you just need to create a “Apache Tomcat” server and specify the server location to that of a previously downloaded TomEE instance.

That’s pretty much all that is involved in getting up and running with TomEE and NetBeans. TomEE offers a fast Java EE 6 certified stack that provides for rapid development and deployment of applications, whereas NetBeans 7.3 provides excellent tooling to support TomEE and Java EE development.

I Miss Dependancy Injection

I’ve just started working on a fairly small web application project that uses Struts as its web framework. I like Struts, its fairly simple to use and covers just about everything I need for my application.

Since I’m now using NetBeans 5 Beta 2 (eventually!), I though I would have a read of Geertjan’s series of articles on how to use Struts with NetBeans. These are good articles if you are new to Struts or want to see how NetBeans handles Struts development.

However, since I’ve used Spring in the past, Geertjan’s method of grabbing database connections seems odd. I’m not detracting in any way from the series of articles (which are great) which are intended to discuss struts development with NetBeans – this is more of a problem I have with Struts.

Once you get into the rhythm of using DI, it seems strange going back to explicitly setting things up. For example datasources – injecting datasources directly into DAOs is one of the best things that I like about Spring and something that seems completely unnecessary now when using Struts.

Struts is Alive !!

There has been a lot of talk recently about the demise of Struts. Its true that there haven’t been any major developments recently on the core product. However looking at the most popular blogs on Javablogs.com today shows that there is still a huge interest in Struts. 5 out of the top 6 read blogs are relating to the merger of Struts and WebWork.

Maybe everyone just finds this an interesting story, or maybe they just want to read about products that they used to use, or maybe people are still using Struts and are interested in what the future will bring ;) .

Whatever your point of view, this is interesting news.

Struts is alive !!

How (not) to choose a web framework…

How do you know which web framework to use when starting a new project? It can be tricky and there are several factors which can influence your decision, such as support, learning curve, project standards etc.

To help people choose their web framework, I’ve done a totally un-scientific survey and found out how many times a framework is mentioned on www.javablogs.com

The results are:

Spring 3439
Struts 3032
JSF 1278
WebWork 1209
Tapestry 1081

I don’t think you can draw any conclusions from this apart from the fact that javablogs.com has a search facility!!

Struts and JSF Support in NetBeans

It seems that we are going to get much tighter integration with Struts and JSF in NetBeans 4.2.

Geertjan describes whats going to be available in NetBeans 4.2. It looks as though Struts and JSF will be tightly integrated – the whole process of creating a new project using these technologiues can be described in 4 pictures!

Its not difficult to create a Struts project in NetBeans 4.1, but little things like this make the IDE so much nicer.