EJB components obtain database connections using JNDI. The EAServer component and package properties bind data source to the JNDI names used in the component implementation.
When we deployed the EJB-JAR file, EAServer bound the JNDI data source names to the default data source. We must reconfigure the properties to use the new data source that we just created.
Changing the data source used by the EJB components
In the Management Console, expand the EJB Modules folder and click on the ejbtut icon beneath it. The package configuration properties display.
Display the Configuration tab. This tab displays the Ant configuration file that EAServer generated from the settings in the EJB-JAR deployment descriptor. Since this configuration file is regenerated if you redeploy the components, we will not modify it. Instead we will create a user-configuration file.
Right-click the ejbtut icon beneath the EJB Modules folder and choose Create User Configuration. You see a dialog saying the User Configuration File is created. Right-click the ejbtut icon again and choose Refresh to display the User Configuration tab.
Click the User Configuration Tab to display the file contents. The configuration information is the XML text of an Ant build file that sets the package and component properties.
Add the following line above the import
elements
to define the data source name that the components connect to:
<property name="sql.dataSource" value="Glossary"/>
Find the definition of the configure-user
target,
and add the statements below inside the start and end tags for the
target. The target definition in your file should look like this:
<target name="configure-user"> <echo level="info" message="configure: ejbjar-ejbtut-user"/> <echo level="info" message="sql.dataSource is ${sql.dataSource}"/> </target>
Click Apply at the bottom of the page to save the changes.
Structure of the configuration file
The generated configuration file contains several Ant property elements. These
define values that can be used in subsequent setProperties tasks.
In this case, the sql.dataSource property is
used in the setProperties task for the ejbtut
package, to bind the JNDI name to the data source name. By setting
this property in the user configuration file, you have overridden
the definition of the same property in the generated configuration
file. The commands in the generated configuration file bind the
datasource name (specified by the Ant property) to the JNDI name
used in the component code (specified by the EJB-JAR deployment
descriptor).
Right-click on the ejbtut icon beneath the EJB Modules folder and choose Run Ant Recompile. The Management Console runs the Recompile task defined in the configuration file, applying the changes to the package and component properties and regenerating the runtime classes required to integrate the components into EAServer.
Review the output that displays in the right pane. You see Build Successful at the bottom of the output if everything goes ok.