Create Java Project
Next we need to create a Java project. We’ll keep the source separate from the bin directory:
- Pull down the File menu and select New:Project
- Select Java Project and click on Next
- Enter a project name: **
**, again read [this](JPA_Tutorial_1_Getting_Started#SideBarJpaClassPath) to know why I did not use a space in the project name. - Make sure “Create new project in workspace” is selected.
- Make sure the JRE selected is 1.5.x or higher. If such a JRE does not show in the list, you can add it through Window->Preferences->JAVA->Installed JRE’s.
- Select Create separate source and output folders
- Click Finish
Create folders and packages
- Expand your **
** folder - Select the src directory
- Right-click, select new:Folder
- Use the name META-INF
- Make sure **
** is still selected, right-click and select **New:Source Folder** - Enter test and click OK
Add Required Libraries
We now need to add two libraries. Note that these steps assume you’ve already worked through the first tutorial and are working in the same workspace. If you, you’ll need to create user libraries. Review Creating User Libraries.
- Edit the project properties. Select your **
** and either press **alt-enter** or right-click and select properties. - Select Java Build Path
- Click on the Libraries tab
- Click on Add Library
- Select User Libraries and click Next
- Select JPA_JSE by click on the check box
- Click OK
- Click on Add Library again
- Click on JUnit
- Click Next
- In the pull-down list, select JUnit 4
- Click Finish
- Click OK
If you’d like some background information on JUnit, please go here.
Configure Persistence Unit
title: JpaPersistenceUnit —
We now need to create the Persistent Unit definition. We are going to create a file called persistence.xml in the src/META-INF directory with the following contents:
persistence.xml
The Steps
- Expand your **
** - Select the src directory
- Find the src/META-INF directory (if one does not exist, right-click, select New:Folder, enter META-INF and press enter)
- Right click the src/META-INF, select new:File.
- Enter persistence.xml for the name and press “OK” (Note: all lowercase. It won’t make a difference on Windows XP but it will on Unix.)
- Copy the contents (above) into the file and save it
Comments