Next we need to start eclipse and create a workspace.
Create Initial Project
- Start eclipse.
- When prompted, enter a directory for your workspace. I used C:\workspaces\JpaAndEjb3. To understand why I recommend not using a space in the name, read this sidebar.
- Close the Welcome window
User Library
We are going to define a user library, which is just a collection of jar files with a name. Once we create this, we can add it to our classpath with one command. This also makes setting up new projects in the same workspace a snap. We can also export workspace settings and import them into a new workspace.
- Pull down Window:Preferences
- Navigate to Java:Build Path:User Libraries
- Click on New
- Enter JPA_JSE for the name and click on OK
Now we need to add several jars to this list. For each of the following jars, do the following:
- Select JPA_JSE (after you add the first one, you’ll have to go back and click the library, which seems to be a poor UI design)
- Click on Add JARs…
- Navigate to the jar file
- Select the jar file
- Click on Open
- Repeat at step one.
Here is a list of all the jar files you’ll need to add (note the path’s listed assume you extracted your jar files to C:/libs):
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 Next
- Enter a project name: JpaTutorial1, again read this sidebar 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. If a 1.5 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 project JpaTutorial1
- Select the src folder
- Right-click, select new:Folder
- Enter the name META-INF
- Click Finish
- Select the src folder again
- Right-click, select new:Package
- Enter the name entity
- Click on Finish
- Select the Tutoria1 project again
- Right-click, select new:Source Folder
- Enter the name test
- Click Finish
- Select the test folder
- Right-click, select new:Package
- Enter the name entity
Add Required Libraries
We now need to add two libraries. One will be the user-defined library we created above. The second will be JUnit 4.x.
- Edit the project properties. Select your project (e.g. JpaTutorial1) 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 clicking on the checkbox
- Click OK
- Click on Add Library again
- Click on JUnit
- Click Next
- In the pull-down list, select JUnit 4
- Click Finish
- Click OK
Comments