Resource Declarations
<env-entry> <!-- expect simple parameter --> <description>Configure time zone</description> <!-- optional --> <env-entry-name>param/timezone</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>EST</env-entry-value> <!-- optional --> </env-entry>
Environment Entry Example
<env-entry> describes settings that a deployer can use to configure a web application in the web container. Here are some simple example entries:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <env-entry> <description>Admin Name</description> <env-entry-name>param/adminName</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>(unknown)</env-entry-value> </env-entry> <env-entry> <description>Set to "true" to run in development mode</description> <env-entry-name>param/developmentMode</env-entry-name> <env-entry-type>java.lang.Boolean</env-entry-type> <env-entry-value>false</env-entry-value> </env-entry> <env-entry> <description>Maximum login attempts before user will be locked out</description> <env-entry-name>param/maxLoginAttempts</env-entry-name> <env-entry-type>java.lang.Integer</env-entry-type> <env-entry-value>5</env-entry-value> </env-entry> </web-app>
<resource-ref> <!-- expect reference to connection factory --> <description>My DataSource</description> <!-- optional --> <res-ref-name>jdbc/MyDataSource</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <!-- Container or Application --> <res-sharing-scope>Shareable</res-sharing-scope> <!-- optional (default: Shareable) --> </resource-ref> <resource-env-ref> <!-- expect reference to a complex object --> <description>Configuration bean</description> <!-- optional --> <resource-env-ref-name>my/ConfigBean</resource-env-ref-name> <resource-env-ref-type>com.jarfiller.beans.ConfigBean</resource-env-ref-type> </resource-env-ref>
Resource Reference Example
<resource-ref> is mostly used for JDBC DataSource or JMS ConnectionFactory instances. It is not that important these days, but can be used for passing beans to the application (if the container supports this).
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <resource-ref> <res-ref-name>jdbc/MyDataSource</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> <resource-ref> <res-ref-name>jms/MyConnectionFactory</res-ref-name> <res-type>javax.jms.ConnectionFactory</res-type> <res-auth>Container</res-auth> </resource-ref> <resource-env-ref> <resource-env-ref-name>my/ConfigBean</resource-env-ref-name> <resource-env-ref-type>com.jarfiller.beans.ConfigBean</resource-env-ref-type> </resource-env-ref> </web-app>
<ejb-ref> <!-- expect reference to EJB via remote interface --> <description>Sets TimeManager EJB</description> <!-- optional --> <ejb-ref-name>ejb/TimeManagerRemote</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>com.jarfiller.tm.TimeManagerHome</home> <remote>com.jarfiller.tm.TimeManagerRemote</remote> <ejb-link>TimeManager</ejb-link> <!-- optional --> </ejb-ref> <ejb-local-ref> <!-- expect reference to EJB via local interface --> <description>Sets TimeManager EJB</description> <!-- optional --> <ejb-ref-name>ejb/TimeManagerLocal</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home>com.jarfiller.tm.TimeManagerLocalHome</local-home> <local>com.jarfiller.tm.TimeManagerLocal</local> <ejb-link>TimeManager</ejb-link> <!-- optional --> </ejb-local-ref>
EJB Reference Example
<ejb-ref> and <ejb-local-ref> are mostly useful for old EJB 1.x/2.x beans, as home interfaces are not required for EJB 3.x anymore. When writing for the Servlet 2.5 API, you should probably use the @EJB annotation.
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <ejb-ref> <ejb-ref-name>ejb/TimeManagerRemote</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>com.jarfiller.tm.TimeManagerHome</home> <remote>com.jarfiller.tm.TimeManagerRemote</remote> </ejb-ref> <ejb-local-ref> <ejb-ref-name>ejb/TimeManagerLocal</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home>com.jarfiller.tm.TimeManagerLocalHome</local-home> <local>com.jarfiller.tm.TimeManagerLocal</local> </ejb-local-ref> </web-app>
<service-ref> <!-- expect a reference to a web service --> <description>My Webservice</description> <!-- optional --> <display-name>service1</display-name> <!-- optional --> <service-ref-name>service/jfservice</service-ref-name> <service-interface>com.jarfiller.example.JarFillerService</service-interface> <wsdl-file>WEB-INF/wsdl/jarfiller.wsdl</wsdl-file> <!-- optional --> <jaxrpc-mapping-file>WEB-INF/mapping.xml</jaxrpc-mapping-file> <!-- optional --> <service-qname xmlns:jf="http://jarfiller.com/ws"> <!-- optional --> jf:JFHelloService <!-- note the "jf" prefix --> </service-qname> <port-component-ref> <!-- optional, one per interface --> <service-endpoint-interface></service-endpoint-interface> <enable-mtom>false</enable-mtom> <!-- optional --> <port-component-link></port-component-link> <!-- optional --> </port-component-ref> <handler> <!-- optional, one per handler, only for JAX-RPC --> <description>My Handler</description> <!-- optional --> <display-name>handler1</display-name> <!-- optional --> <handler-class>com.jarfiller.example.WSHandler</handler-class> <init-param> <!-- optional, one per parameter --> <param-name>email</param-name> <param-value>tim@jarfiller.com</param-value> </init-param> <soap-header xmlns:jf="http://jarfiller.com/ws"> <!-- optional, one per header --> jf:jfSecToken </soap-header> <soap-role>next</soap-role> <!-- optional, one per role --> <port-name>Port1</port-name> <!-- optional, one per port name --> </handler> </service-ref>
Webservice Reference Example
This example shows a reference to a JAX-WS webservice:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd" version="2.5"> <service-ref> <service-ref-name>service/jfservice</service-ref-name> <service-interface>com.jarfiller.example.JarFillerService</service-interface> <wsdl-file>WEB-INF/wsdl/jarfiller.wsdl</wsdl-file> <service-qname xmlns:jf="http://jarfiller.com/ws">jf:JFHelloService</service-qname> </service-ref> </web-app>
<message-destination-ref> <!-- expect reference to a JMS queue or topic --> <description>My queue reference</description> <!-- optional --> <message-destination-ref-name>jms/MyQueue</message-destination-ref-name> <message-destination-type>javax.jms.Queue</message-destination-type> <message-destination-usage>Produces</message-destination-usage> <message-destination-link>JFQueue1</message-destination-link> <!-- optional --> </message-destination-ref> <message-destination> <!-- declares a JMS queue or topic --> <description>My destination</description> <!-- optional --> <display-name>A test destination.</display-name> <!-- optional --> <message-destination-name>JFQueue1</message-destination-name> </message-destination>
Message Destination Example
This example shows a simple declaration of a JMS ConnectionFactory and a Queue to send messages:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <resource-ref> <res-ref-name>jms/ActiveMQConnectionFactory</res-ref-name> <res-type>javax.jms.ConnectionFactory</res-type> <res-auth>Container</res-auth> </resource-ref> <message-destination-ref> <description>Order Queue</description> <message-destination-ref-name>jms/Orders</message-destination-ref-name> <message-destination-type>javax.jms.Queue</message-destination-type> <message-destination-usage>Produces</message-destination-usage> <message-destination-link>OrderQueue</message-destination-link> </message-destination-ref> <message-destination> <message-destination-name>OrderQueue</message-destination-name> </message-destination> </web-app>
This next example shows a simple declaration of a JMS ConnectionFactory and a Topic that receives messages:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <resource-ref> <res-ref-name>jms/ActiveMQConnectionFactory</res-ref-name> <res-type>javax.jms.ConnectionFactory</res-type> <res-auth>Container</res-auth> </resource-ref> <message-destination-ref> <description>Messages to update the site</description> <message-destination-ref-name>jms/SiteUpdates</message-destination-ref-name> <message-destination-type>javax.jms.Topic</message-destination-type> <message-destination-usage>Consumes</message-destination-usage> </message-destination-ref> </web-app>

