EJB3.0 in Netbeans 5.0

Over the past few weeks, several articles about EJB3.0 have been published on our weblog.
On Thursday, 10 Februari 2006, the author of those articles, Lucas
Jellema, presented a workshop about EJB3.0 at AMIS. This workshop
contained HOWTOs to get EJB3.0 working in Eclipse and JDeveloper. Using
the workshop material I tried to do the workshop in Netbeans 5.0.

Searching the Netbeans homepage reveals that no EJB3.0 support yet exists in Netbeans. This makes perfectly good sense since the EJB3.0 specs still are in draft status. And EJB3.0 needs help from JEE5 which also isn’t final yet. So if you want to start playing around with EJB3.0 in Netbeans, you’ll have spice Netbeans up with beta jars. This article tells you how I did it.

First of all, please note that I will not go into the details of EJB3.0 at all. For that, please refer to Lucas’ articles on our weblog. Having said that, let’s go.

For all of this to actually work, you’ll need to download some software. Of course you’ll need Netbeans. I downloaded the latest and greatest version of Netbeans at the time of this writing, which is Netbeans 5.0. Please refer to the Netbeans homepage for downloads and installation instructions. Next to Netbeans, you’ll need the GlassFish JEE5 application server. Basic installation instructions can be found on the GlassFish downloads page. Next, follow the instructions on the GlassFish QuickStart Guide page to verify your install. After having verified you installed GlassFish correctly you can stop it again. You won’t be needing it anymore for now. You just need some jars that are shipped with GlassFish.

Start Netbeans if you haven’t already done so. In Tools -> Library Manager create a new Library, call it “EJB3.0” (or whatever you like) and make sure these jars from GlassFish are included:

  • antlr.jar
  • asm-attrs.jar
  • asm.jar
  • javaee.jar
  • toplink-essentials-agent.jar
  • toplink-essentials.jar

Besides that you’ll need JDBC drivers for your database. I used an Oracle database, so I also created a Library that contains these jar files:

  • dms.jar
  • jdbc-thin-10.2.0.1.jar
  • ocrs12.jar
  • ojdbc14dms.jar
  • orai18n.jar

and I called this Library “Oracle JDBC”.

Create a new Project and choose “General” and “Java Application”. After creating the Project is completed, add a new Folder to the Project and name this folder “META-INF”. This folder will contain our persistence.xml file and in a few moments we’ll add this directory to the Sources list of the Project. Because of its name, Netbeans will add the contents of this folder to the “classes” folder in the build directory. However, the EJB3.0 specs require the persistence.xml file not to be directly under the “classes” directory, but in a directory called META-INF under the “classes” directory. In order to resolve this issue, create a new Folder in the META-INF folder called META-INF and place the persistence.xml file in that folder. Damn this is ugly, but at least it works…

Next, open the Project properties by right clicking the project name in the Projects navigator and choosing “Properties”. In the Spurces category, click “Add folder”, select META-INF and click open. Then select the Run category. Make sure the Working Directory is set to the directory in which GlassFish is installed. Also, add this string

-javaagent:C:\glassfish\lib\toplink-essentials-agent.jar

and make sure the path behind the first colon points to the toplink-essentials-agent.jar file in your local GlassFish install dir.

EJB3.0 in Netbeans 5.0 project properties

That’s it! Now you can create your POJOs and persistence.xml and everything should be fine. If not, add a comment to this article and I’ll try to help you.

4 Comments

  1. Wouter van Reeven February 26, 2006
  2. Avinash Rawana February 26, 2006
  3. Wouter van Reeven February 13, 2006
  4. vince kraemer February 12, 2006