Creating and configuring resource references for Web 2.5, Web 3.0, Web 3.1, and Web 4.0
You can create and configure resource references for Web 2.5, Web 3.0, Web 3.1, and Web 4.0 projects using the deployment descriptor.
About this task
Procedure
- Expand your web project, and select WebContent > WEB-INF > web.xml.
- Right-click web.xml and select Open with > Web Application Deployment Descriptor Editor.
-
In the Web application field, select Add and
select Resource Reference and click OK:
-
In the Details section, provide
the details for your resource reference:
- In the Name field, provide a name for your resource reference.
- In the Type field, provide the type of resource reference.
- In the Authentication field, select either Application or Container for the authentication of your resource reference.
- In the Sharing Scope field, select either Shareable or Unshareable for the sharing scope of your resource reference.
- In the Description field, type a description of this resource reference.
-
To view the web.xml source code, select Source:
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <servlet> <description> </description> <display-name> TestServlet</display-name> <servlet-name>TestServlet</servlet-name> <servlet-class>test.TestServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern> /TestServlet</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <resource-ref> <res-ref-name>SAMPLE</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> </web-app>
- To edit your resource reference, you can make changes in either the Design or the Source view of the deployment descriptor page.
-
To bind this resource reference to a data source on the
server, with the JNDI name jdbc/SAMPLE using a JAAS authentication
alias called USER_AUTH, edit the ibm-web-bnd.xml file
and add the following definitions:
- If the ibm-web-bnd.xml file does not exist, create the file by right-clicking on the project and then selecting Java EE tools > Generate WebSphere Bindings Deployment Descriptor.
- Right-click the ibm-web-bnd.xml file and select Open with > Web Bindings Editor.
-
Add a resource reference:
- In the Design view, click Add.
- In the Add Item window, select Resource Reference. Click OK.
- In the Name field, type the name of your resource reference, for example: SAMPLE.
- In the Binding Name field, type the name of your resource reference, for example: jdbc/SAMPLE.
- In the Design view, highlight your Resource Reference, and click Add > Authentication Alias.
-
In the Details section, in the Name field,
provide a name for your Authentication Alias (for example, use the
JAAS authentication alias called USER_AUTH).
- Save the file.
-
To view the ibm-web-bnd.xml source
code, select Source:
<?xml version="1.0" encoding="UTF-8"?> <web-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd" version="1.0"> <virtual-host name="default_host" /> <resource-ref name="SAMPLE" binding-name="jdbc/SAMPLE"> <authentication-alias name="USER_AUTH" /> </resource-ref> </web-bnd>