Part I Development Tasks and Tools
1. Setting Up a Development Environment
Part II Developing Applications and Application Components
6. Using the Java Persistence API
7. Developing Web Applications
8. Using Enterprise JavaBeans Technology
9. Using Container-Managed Persistence
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 EJB Components Using the CosNaming Naming Context
Accessing EJB Components in a Remote GlassFish Server
Naming Environment for Lifecycle Modules
Using a Custom jndi.properties File
The GlassFish Server exposes special resources in the naming environment.
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:
To create an external JNDI resource using the Administration Console, open the Resources component, open the JNDI component, and select External Resources. For details, click the Help button in the Administration Console.
To create an external JNDI resource, use the asadmin create-jndi-resource command. For details, see the Oracle GlassFish Server 3.1-3.1.1 Reference Manual.
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:
To create a custom resource using the Administration Console, open the Resources component, open the JNDI component, and select Custom Resources. For details, click the Help button in the Administration Console.
To create a custom resource, use the asadmin create-custom-resource command. For details, see the Oracle GlassFish Server 3.1-3.1.1 Reference Manual.
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.
To create a custom resource that provides instances of a JavaBean class, follow these steps:
Set the custom resource's factory class to org.glassfish.resources.custom.factory.JavaBeanFactory.
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.
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.
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:
Create a property in the custom resource named org.glassfish.resources.custom.factory.PropertiesFactory.fileName and specify as its value the path to a properties file or an XML file.
The path can be absolute or relative to as-install. The file must be accessible to the GlassFish Server.
If an XML file is specified, it must match the document type definition (DTD) specified in the API definition of java.util.Properties.
Create the desired properties directly as properties of the custom resource.
If both the fileName property and other properties are specified, the resulting property set is the union. If the same property is defined in the file and directly in the custom resource, the value of the latter takes precedence.
To create a custom resource that provides Java primitives to applications, follow these steps:
Set the custom resource's factory class to org.glassfish.resources.custom.factory.PrimitivesAndStringFactory.
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
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.
To create a custom resource that provides URL instances to applications, follow these steps:
Set the custom resource's factory class to org.glassfish.resources.custom.factory.URLObjectFactory.
Choose which of the following constructors to use:
URL(protocol, host, port, file)
URL(protocol, host, file)
URL(spec)
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.
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:
Enables the automatic use of GlassFish Server V2–specific JNDI names. This is the default setting.
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.
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.