02 April 2008

NetBeans6.1+EJB3+Struts [PART 1]

Hi all, I just decided to start a blog and with the new blog comes already a review about the new NetBeans 6.1, still in beta phase but incredibly stable and FAST.

In this tutorial we will use NetBeans 6.1 Web & Java EE version.
This is the list of software one might need:

  • JDK 1.5
  • GlassFish V2 UR1
  • some database (I will use for this tutorial java db but mysql is also a good option)

NetBeans 6.1 Web & Java EE comes already bundled with GlassFish and Tomcat. In just 105 mb!!!. It's awesome to download just one package and a small one.

With NB6.1 you will see how fast it can be to configure/create/code with it.
I will assume that you have already a table in one database of your preference.

After downloading, installing and running NetBeans you will need to create a new project.

Click in File->New Project...choose Enterprise and then Enterprise Application.

Inside the Enterprise Application NetBeans will automatically create for you an EJB Module and Web Application Module.

Type MyApp in the Project Name and leave all of the other settings as it is.

Click in Next and Finish.

Notice that in on the left side in the Projects tab 3 modules were added: MyApp, MyApp-ejb and MyApp-war.

Right click on MyApp-ejb and select New->Other->Persistence->Persistence Unit.

Click in the dropdown box in Data Source and select your DB connection. Then in Table Generation Strategy select create. And leave Use Java Transaction APIs selected.

Once Finish is clicked a persistence.xml tab will open.

The persistence unit will tell your container how the entities will be persisted and managed in the application.

Now right click again in MyApp-ejb and select New->Entity Classes from Database.

In Data Source select the JNDI name that you have configured and the tables will appear in the right side of the panel, select the table you want to create the Java Classes and click in Add>

No comments: