Port of schuchert.wikispaces.com


EJB3_Tutorial_1_Create_and_Configure

EJB3_Tutorial_1_Create_and_Configure

title: Ejb3EclipseUserLibrarySetup —

Define User Library

We need to add several jar files to the class path. We created a user library in these steps and we’re going to do the same thing with a different set of jar files.

Create User Library

  • Pull down Window:Preferences
  • Navigate to Java:Build Path:User Libraries
  • Click on New
  • Enter EJB3_EMBEDDABLE for the name and click on OK

Add Jars to User Library

Now we need to add all of the jar files from the lib directory under the JBoss Embeddable container directory we unzipped earlier:

  • Select EJB3_EMBEDDABLE
  • Click on Add JARs…
  • Navigate to C:/libs/jboss-EJB-3.0_Embeddable_ALPHA_9/lib/
  • Select all of the the jar files
  • Click on Open

You need to add all of the jar files from the lib directory under the JBoss Embeddable container directory. If you used the same directory as the tutorial, then you need add all of the jar files from C:/libs/jboss-EJB-3.0_Embeddable_ALPHA_9/lib/ (there are 5). Here is the complete list of jar files:

  • C:/libs/jboss-EJB-3.0_Embeddable_ALPHA_9/lib/thirdparth-all.jar
  • C:/libs/jboss-EJB-3.0_Embeddable_ALPHA_9/lib/hibernate-all.jar
  • C:/libs/jboss-EJB-3.0_Embeddable_ALPHA_9/lib/jboss-ejb3-all.jar
  • C:/libs/jboss-EJB-3.0_Embeddable_ALPHA_9/lib/jcainflow.jar
  • C:/libs/jboss-EJB-3.0_Embeddable_ALPHA_9/lib/jms-ra.jar

Create and Setup Project

For the rests of this tutorial, when you see **** replace it with **Ejb3Tutorial1**.


title: Ejb3EclipseProjectSetupAndConfiguration —

Create the Project

  • Pull down the File menu and select new:project
  • Select Java Project
  • Click Next
  • Enter ****
  • Under Project Layout select create separate source and output folders
  • Click Finish
  • Select ****, right-click and select **new:Source Folder**
  • Enter conf for the name
  • Click on Finish
  • Select ****, right-click and select **new:Source Folder**
  • Enter test for the name
  • Click on Finish

Edit your project properties

Now that we have created a user library, we can add that user library to our project:

  • Select ****, and press alt-enter or right-click and select properties.
  • Select Java Build Path
  • Select the Libraries tab
  • Click on Add Library
  • Select User Library and click Next
  • Click on the box next to EJB3_EMBEDDABLE and click Finish
  • Click Add Library
  • Select JUnit and click Next
  • In the pull-down list, select JUnit 4 and click Finish
  • Click on OK to make the change to your project’s classpath

Setup the configuration files

The JBoss Embeddable container looks for several files in the classpath. To keep all of these in one place, we’ll add another source directory to our project and then import several files into that directory.

  • Select the conf folder under ****
  • Pull down the File menu and select Import
  • Expand General
  • Select File System and click on Next
  • Click on Browse and go to the following directory: C:/libs/jboss-EJB-3.0_Embeddable_ALPHA_9/conf
  • Click on OK
  • You’ll see conf in the left pane, select it
  • Verify that the Into folder: lists **/conf** (if not, just enter it or browse to it)
  • Click Finish
  • Expand the conf directory and verify that the files are now there

Add Resource Adapter Archive(RAR)

The Java Connector system defines Resource Adapter Archive files (RAR files). We need to add a few RAR files into the class path. We will import two more files into the conf directory:

  • Select the conf folder
  • Pull down the File menu and select Import
  • Expand General
  • Select File System and click on Next
  • Click on Browse and go to the following directory: C:/libs/jboss-EJB-3.0_Embeddable_ALPHA_9/lib
  • Select jcainflow.rar and jms-ra.rar
  • Click Finish

Create a jndi.properties file

Note, depending on the version of the embeddable container you download, you might already have a file called jndi.properties. If you do, skip to the next section.

  • Select the conf directory, right-click and select new then select File
  • Enter the name jndi.properties and click finish
  • Enter the following 2 lines then save and close the file:
java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Create a persistence.xml

This example presents a utility class we’ll be using later. The container needs a persistence.xml file to operate. This file must be found under a META-INF directory somewhere in the classpath or the embeddable container will not start. The file’s name is persistence.xml with a lower-case ‘p’. On a Unix system, this will make a difference. On a PC, this won’t make a difference and it is one of those things that might work on your machine but not on the linux build box.

  • Select your src directory
  • Right-click, select New:Folder
  • Enter META-INF
  • Click OK
  • Select META-INF
  • Right-lick, select New:File
  • Enter persistence.xml
  • Click Finish
  • Copy the following example into your new file then save it by pressing ctrl-s

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence>
   <persistence-unit name="custdb">
   
    <!-- This persistence unit uses the default data source that JBoss    -->
    <!-- defines called DefaultDS. If we wanted to use our own data       -->
    <!-- source, we'd need to define a custom data source somewhere.      -->
    <!-- That somewhere is vendor specific.                               -->
    
    <!-- In the case of JBoss, since we're using the embedded container,  -->
    <!-- we need to add two beans in a file called                        -->
    <!-- embedded-jboss-beans.xml. We name the first                      -->
    <!-- HypersonicLocalServerDSBootstrap and we name the second          -->
    <!-- HypersonicLocalServerDS. This two step process defines a data    -->
    <!-- source.                                                          -->
    
    <!-- In the first bean definition, we additionally bind it in Jndi    -->
    <!-- under some name. If we used the name                             -->
    <!-- java:/HypersonicLocalServerDS then we would use the following    -->
    <!-- entry to use that data source instead of the default one:        -->
    <!-- <jta-data-source>java:/HypersonicLocalServerDS</jta-data-source> -->
 
      <jta-data-source>java:/DefaultDS</jta-data-source>
      <properties>
         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
      </properties>
   </persistence-unit>
</persistence>

Comments

" Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.