Archive for January, 2008

Making Petstore work in NetBeans 6.0

Sunday, January 27th, 2008

The Petstore sample application from Sun demonstrates a wide range of technologies. It is available in a number of downloads from Sun and is organized in the Blueprints format for projects. However it cannot just be run as it appears on a Windows system. After searching for and reading question and answers about Petstore I have come up with the following steps that worked for me. What follows are the steps necessary to get Petstore to work on a Windows system with NetBeans 6.0.

Assumptions:
Glassfish is installed in C:/glassfish-v2
The user name for Glassfish is admin and the password is adminadmin.

Step 1:
Download the javapetstore-2.0-ea5-installer.jar file from Sun. I found it at https://blueprints.dev.java.net/petstore/

Step 2:
Use javapetstore-2.0-ea5-installer.jar. Execute this jar file (double-click on it) and it will unzip itself in its current directory in a folder called javapetstore-2.0-ea5. Move this directory to the location of your choice for the project. In the remaining instructions it is assumed that you moved it to C:\javapetstore-2.0-ea5

Step 3:
Locate the file build.properties found in C:\javapetstore-2.0-ea5\bp-project\ and open it with a text editor to make the following changes.

Step 4:
Change javaee.home from:
javaee.home=c:/Sun/SDK
to
javaee.home=C:/glassfish-v2

Step 5:
Change javaee.server.passwordfile from:
javaee.server.passwordfile=${javaee.home}/samples/bp-project/passwordfile
to
javaee.server.passwordfile= C:/javapetstore-2.0-ea5/bp-project/passwordfile

Step 6:
In the C:\javapetstore-2.0-ea5\bp-project folder create a file called passwordfile (no extension).

Step 7:
In this file add the following line:
AS_ADMIN_PASSWORD=adminadmin

Step 8:
Start NetBeans and open the project javapetstore-2.0-ea5 that you will find when you browse to C:\javapetstore-2.0-ea5.

Step 9:
Start the GlassFish server. In NetBeans select Window and then Services. A new panel replaces the Projects panel and displays all the services available. Select Servers, right mouse click on Glassfish, and select Start.

Step 10:
In NetBeans return to the Projects panel in the petstore project, go to the Server Resources folder of the project, right mouse click on setup.xml, select Run Target, and select setup. This should create the necessary database files and register them with the persistence engine of GlassFish.

Step 12:
Now Run the main project.

Moving Projects in NetBeans

Thursday, January 24th, 2008

In a course I am teaching on the subject of Enterprise Java Beans 3.0 I am using NetBeans 6.0. In all my other Java courses I have used Eclipse. But I find Eclipse’s EJB tools not as well integrated as NetBeans. In a classroom environment it is necessary for students to move their work from school to home and back again. This is where I encountered a problem.

For reason’s known only to the developer’s of IDEs like Eclipse or Netbeans, locations of files are hard coded in files stored somewhere in the directory structure of the project. If you do all your development work on a single computer or if you use a version control system then you never encounter the problem of moving projects. But I do my class preparation on three different computers and then do  my presentation in the lab on a fourth computer. And I have different directory structures on these computers and I even have different login names.

When I encountered the problem I did what every good programmer does, I searched the web for a solution. I couldn’t be the only person who had this problem. Well, to my surprise I seem to be the only person. I could not find a reference to how I might move a project from one computer to another. So I spent a day reading XML files and found the solution.

In a NetNeans Enterprise application, EJB, web client, and app client project there are directories named nbprojects. In these directories is a folder called private. Just delete the private directory in every nbproject folder. Now you can open the Application project and the EJB and client projects will be located and opened with the application.

After discovering this I examined sample projects from Sun. The layout of all these projects conforms to a standard called blueprints. All the Sun sample projects already have the private folder removed. So now my students and I can copy a project to our flash drives, bring them home, delete the private folders, and continue working.