Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Know your Oracle application server

Troubleshooting OC4J and WebLogic for Java EE application deployment

  • Print
  • Feedback

Page 4 of 6

Context context = new InitialContext();
JavaWorld javaWorld = (JavaWorld)context.lookup("ejb/JavaWorld");

For WebLogic server, you must use:

Context context = new InitialContext();
JavaWorld javaWorld =
    (JavaWorld)context.lookup("ejb/JavaWorld#datamodel.logic.JavaWorld");

In the last line of this code, the value of the mappedName attribute precedes the #, and the package plus the Java class name of the business interface follows the #. Note that the mappedName attribute is used to refer to resources configured in the entire application server, not just the application. OC4J doesn't support this attribute.

Configuring resources

In general, it's preferable to configure resources in an application server instead of doing all the coding yourself. A Java Message Service (JMS) service is one such resource. JMS is a messaging standard that lets EJB components create, send, receive, and read messages. To configure a JMS provider on a WebLogic server, you must follow a few steps:

  1. Create a persistence store -- a physical repository for storing data related to the system.
  2. Create a JMS server -- a container that manages queues and topics.
  3. Configure JMS resources, such as queues and topics, as JMS modules.
  4. Create a sub-deployment -- a mechanism that groups JMS resources and binds them to the JMS server.
  5. Create JMS resources -- queues, topics, and connection factories. Queues and topics are destinations that a client can specify as the target or the source, respectively, of the produced or consumed messages. A connection factory is used to connect to a JMS server.

Next, add the persistent store, JMS server, and the JMS modules to the config.xml file in the domain-home/config directory. Put the JMS resources into a separate file located in the domain-home/config/jms directory. This file contains the provided JNDI names. If you use OC4J, you must add the JMS resources to the jms.xml file located in the oc4j-home/config directory.

Resource injection

Java EE lets you retrieve configured resources by using resource injection. Suppose you have configured a connection factory and registered it using the JNDI name jms/JavaWorld. With OC4J, you can retrieve this resource by using:

@Resource(name = "jms/JavaWorld")
private ConnectionFactory javaWorld;

On a WebLogic server, resource injection is not supported by itself. If a certain enterprise bean wants to use configured resources, you must add these resources to the weblogic-ejb-jar.xml file. This file, which defines the beans, can be used to override certain deployment settings. Of course you can still use a JNDI lookup to retrieve the resource.

If an application is being deployed, you can also create a deployment plan that contains various module-override sections. This example deployment-plan section specifies a number of files in which you can define the overrides:

<weblogic-ejb-jar...>
  <weblogic-enterprise-bean>
    <ejb-name>JavaWorld</ejb-name>
    <enable-call-by-reference>True</enable-call-by-reference>
    <jndi-name>ejb/JavaWorld</jndi-name>
  </weblogic-enterprise-bean>
</weblogic-ejb-jar>

Note that the resources to be used by the enterprise bean can be defined in the deployment plan.

  • Print
  • Feedback

Resources

More from JavaWorld