EJB3.0 in Netbeans 5.0

4

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.

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.

Share.

About Author

4 Comments

  1. Wouter van Reeven on

    Hi Avinash,

    Thanks for your comment. I’m sorry to hear my META-INF structure didn’t work for you. Would you please describe what steps you needed to take to get the persistence.xml file included in the deploy directory? Did you need to tell Netbeans to include it somewhere?

    Thanks, Wouter

  2. Avinash Rawana on

    Hey, here is your structure..

    META-INF –> META-INF —> FileX

    I just tried what you said and it DIDN’T work. The solution was to change..to..

    AnythingOtherThanMETA-INF —> META-INF –> FileX

  3. Wouter van Reeven on

    Vince,

    Many thanks for your kind comment. I have searched both the Netbeans site and Google for stories about EJB3.0 and Netbeans and I wasn’t able to find many, certainly not for Netbeans 5. I will keep an eye at your blog from now on!

    Greets, Wouter