JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle GlassFish Server 3.1 Application Development Guide
search filter icon
search icon

Document Information

Preface

Part I Development Tasks and Tools

1.  Setting Up a Development Environment

2.  Class Loaders

3.  Debugging Applications

Part II Developing Applications and Application Components

4.  Securing Applications

5.  Developing Web Services

6.  Using the Java Persistence API

7.  Developing Web Applications

8.  Using Enterprise JavaBeans Technology

9.  Using Container-Managed Persistence

10.  Developing Java Clients

11.  Developing Connectors

12.  Developing Lifecycle Listeners

13.  Developing OSGi-enabled Java EE Applications

Part III Using Services and APIs

14.  Using the JDBC API for Database Access

15.  Using the Transaction Service

16.  Using the Java Naming and Directory Interface

Accessing the Naming Context

Global JNDI Names

Accessing EJB Components Using the CosNaming Naming Context

Accessing EJB Components in a Remote GlassFish Server

Naming Environment for Lifecycle Modules

Configuring Resources

External JNDI Resources

Custom Resources

Built-in Factories for Custom Resources

JavaBeanFactory

PropertiesFactory

PrimitivesAndStringFactory

URLFactory

Disabling GlassFish Server V2 Vendor-Specific JNDI Names

Using Application-Scoped Resources

Using a Custom jndi.properties File

Mapping References

17.  Using the Java Message Service

18.  Using the JavaMail API

Index

Configuring Resources

The GlassFish Server exposes special resources in the naming environment.

External JNDI Resources

An external JNDI resource defines custom JNDI contexts and implements the javax.naming.spi.InitialContextFactory interface. There is no specific JNDI parent context for external JNDI resources, except for the standard java:comp/env/.

Create an external JNDI resource in one of these ways:

Custom Resources

A custom resource specifies a custom server-wide resource object factory that implements the javax.naming.spi.ObjectFactory interface. There is no specific JNDI parent context for external JNDI resources, except for the standard java:comp/env/.

Create a custom resource in one of these ways:

Built-in Factories for Custom Resources

The GlassFish Server provides built-in factories for the following types of custom resources:

Template glassfish-resources.xml files for these built-in factories and a README file are available at as-install/lib/install/templates/resources/custom/. For more information about the glassfish-resources.xml file, see the Oracle GlassFish Server 3.1 Application Deployment Guide.

JavaBeanFactory

To create a custom resource that provides instances of a JavaBean class, follow these steps:

  1. Set the custom resource's factory class to org.glassfish.resources.custom.factory.JavaBeanFactory.

  2. Create a property in the custom resource for each setter method in the JavaBean class.

    For example, if the JavaBean class has a method named setAccount, specify a property named account and give it a value.

  3. Make sure the JavaBean class is accessible to the GlassFish Server.

    For example, you can place the JavaBean class in the as-install/lib directory.

PropertiesFactory

To create a custom resource that provides properties to applications, set the custom resource's factory class to org.glassfish.resources.custom.factory.PropertiesFactory, then specify one or both of the following:

PrimitivesAndStringFactory

To create a custom resource that provides Java primitives to applications, follow these steps:

  1. Set the custom resource's factory class to org.glassfish.resources.custom.factory.PrimitivesAndStringFactory.

  2. Set the custom resource's resource type to one of the following or its fully qualified wrapper class name equivalent:

    • int

    • long

    • double

    • float

    • char

    • short

    • byte

    • boolean

    • String

  3. Create a property in the custom resource named value and give it the value needed by the application.

    For example, If the application requires a double of value 22.1, create a property with the name value and the value 22.1.

URLFactory

To create a custom resource that provides URL instances to applications, follow these steps:

  1. Set the custom resource's factory class to org.glassfish.resources.custom.factory.URLObjectFactory.

  2. Choose which of the following constructors to use:

    • URL(protocol, host, port, file)

    • URL(protocol, host, file)

    • URL(spec)

  3. Define properties according to the chosen constructor.

    For example, for the first constructor, define properties named protocol, host, port, and file. Example values might be http, localhost, 8085, and index.html, respectively.

    For the third constructor, define a property named spec and assign it the value of the entire URL.

Disabling GlassFish Server V2 Vendor-Specific JNDI Names

The EJB 3.1 specification supported by GlassFish Server 3.1 defines portable EJB JNDI names. Because of this, there is less need to continue to use older vendor-specific JNDI names.

By default, GlassFish Server V2–specific JNDI names are applied automatically by GlassFish Server 3.1 for backward compatibility. However, this can lead to some ease-of-use issues. For example, deploying two different applications containing a remote EJB component that exposes the same remote interface causes a conflict between the default JNDI names.

The default handling of V2–specific JNDI names in GlassFish Server 3.1 can be managed by using the asadmin command:

asadmin> set server.ejb-container.property.disable-nonportable-jndi-names="true"

disable-nonportable-jndi-names is a boolean property that can take the following values:

false

Enables the automatic use of GlassFish Server V2–specific JNDI names. This is the default setting.

true

Disables the automatic use of V2–specific JNDI names. In all cases, 3.1-compatible JNDI names are used.

Note that this setting applies to all EJB components deployed to the server.

Using Application-Scoped Resources

You can define an application-scoped JNDI or other resource for an enterprise application, web module, EJB module, connector module, or application client module by supplying a glassfish-resources.xml deployment descriptor file. For details, see Application-Scoped Resources in Oracle GlassFish Server 3.1 Application Deployment Guide.