I have a web application that requires two settings:
- JDBC Data Source
- Line character
I desperately want to be able to deploy one .war to various containers (berth, tomcat, gf3 minimum) and configure these settings at the application level inside the container.
My code does this:
InitialContext ctx = new InitialContext();
Context envCtx = (javax.naming.Context) ctx.lookup("java:comp/env");
token = (String)envCtx.lookup("token");
ds = (DataSource)envCtx.lookup("jdbc/datasource")
Suppose I used the Glassfish management interface to create two jdbc resources: jdbc / test-datasource and jdbc / live-datasource, which connect to different copies of the same circuit, on different servers, different credentials, etc. Say I want to deploy this to a glass fish and point it to a test data source, I could have this in my sun-web.xml:
...
<resource-ref>
<res-ref-name>jdbc/datasource</res-ref-name>
<jndi-name>jdbc/test-datasource</jndi-name>
</resource-ref>
...
but
- sun-web.xml enters my war, right?
- ,
? ? , Jetty 7 , .
EDIT Tomcat :
$TOMCAT_HOME/conf/Catalina/localhost/webapp.xml :
<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true">
<Environment name="token" value="value of token" type="java.lang.String" override="false" />
<ResourceLink name="jdbc/datasource1" global="jdbc/test" type="javax.sql.DataSource" />
<Resource name="jdbc/datasource2"
type="javax.sql.DataSource"
auth="Container"
driverClassName="org.apache.derby.jdbc.EmbeddedDataSource"
url="jdbc:derby:test;create=true"
/>
<Resource name="jdbc/datasource3"
type="javax.sql.DataSource"
auth="Container"
driverClassName="org.h2.jdbcx.JdbcDataSource"
url="jdbc:h2:~/test"
username="sa"
password=""
/>
</Context>
, override="false" . , web.xml.
, , , ; webapp.
, , -, - .