Tag Archives: NetBeans

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.

Forthcoming Book Reviews

Packt Publishing have recently released two new books of interest to Java EE developers.

EJB 3.1 Cookbook and  Java EE6 With NetBeans 7 both look like good reads and Packt have graciously agreed to send me a copy of each of these books for review, which I’ll post on the site as soon as I’ve reviewed them.

Thanks to Nicole for sorting this out for me.

Introduction to JSF 2 Using NetBeans 6.8 and GlassFish v3

I’ve just published an article entitled, “Introduction to JSF 2 Using NetBeans and GlassFish” over at developinjava.com.

In the article I give a brief introduction to JSF 2 and show how you can create JSF 2 managed beans without XML just by using annotations. I also show how you can localize a JSF 2 application and how the Bean Validation Framework can be used to add server side validation onto POJOs.

The article shows how its becoming much easier to write Enterprise Applications using Java EE 6 with the new annotations that are being added to this version of the platform.

To write the sample application in the article I used NetBeans 6.8M1. I’ve found this version of NetBeans to be remarkably stable and the integration with GlassFish 3 to be excellent.

Starting the Java DB in GlassFish

I’ve been doing a lot of development in NetBeans 5.5 beta 2 recently using Glassfish as my target application server. When doing development, its often quite useful to use the Derby DB bundled within Glassfish. As you’d expect from a modern IDE, NetBeans makes this easier for you by starting the database automatically so you don’t need to worry about it. When you deploy your application to a standalone Glassfish that isn’t “controlled” via NetBeans, you will probably find that the Derby DB doesn’t start automatically when Glassfish starts. Starting the DB is easily done from the command prompt though using the command:

asadmin start-database

Eclipse 3.2 – I don’t think so

With the recent release of Eclipse 3.2 and the Calisto release of 10 Eclipse projects, I thought I would give Eclipse a try.

I’ve not used Eclipse in anger since the 2.x days, however I’ve used it on an off since, but never for my main development. I decided to give Eclipse 3.2 a try on Mac OS (Intel) so my view is tainted by how it works on that particular OS. My comments may or may not be valid on other OS – I don’t know.

To try out Eclipse, I decided to write a few simple web apps – nothing too complicated, simply a few JSPs and JSF backing beans. The first problem I encountered was trying to get support for Glassfish inside Eclipse. There is a plugin availble for this, but this has to be downloaded and installed separately. This isn’t difficult, but a fiddle not the less.

After installing the plugin, I found there are issues with it. It doesn’t always start the server correctly, and nearly always says that it has failed to start the server. If you want a few seconds, sometimes the server is started though. Once I did manage to get the server started from inside Eclipse though, deployment of my application worked as expected. I know this is a bit of an unfair criticism of Eclipse, but if you want to do Java EE 5 development, then Glassfish is a good server to work with. Are there any plans to have “native” support for this in the IDE without having to load a plugin?

The next problem I got with Eclipse 3.2 was the dreaded Permgen error. I’ve not changed any of the memory settings within Eclipse and am using the default values (latest Apple Java 5 VM). Maybe that was my problem. Still, for a very small web app with only a handfull of classes and JSPs I wouldn’t expect to get any Permgen errors.

The final problem I noticed was screen corruption (possibly as a result of the Permgen errors), and also a lot of dialogs have green highlighted text at the bottom of them saying “Read Me Trim (bottom)”. Is this some kind of debug message?

I know there are a lot of Eclipse users out there and I really wanted to like this new version. Maybe its the types of applications I’m writing – Java EE 5 web apps – but Eclipse just doesn’t do it for me.

Sorry Eclipse, I’m going to keep using NetBeans and IntelliJ for now. Maybe I’ll try Eclipse again at version 4.