tags:

views:

423

answers:

3

I am used to configuring web application in context.xml, including jdbc resorces, and application configuration parameters.

Under glassfish, what is considered the standard place to store application configuration information?

We used to store it in the context.xml file as follows:

<Resource
url="jdbc:mysql://localhost:3306/db?useUnicode=true&amp;characterEncoding=utf8"
username="username"
name="jdbc/db"
password="secret"
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxActive="5" maxIdle="2" maxWait="10000"
removeAbandoned="true"
type="javax.sql.DataSource"
/>

<Parameter name="application.url" value="http://localhost:8080/News/" override="false"/>
<Parameter name="smtp.server" value="smtp.example.com" override="false"/>
<Parameter name="smtp.port" value="25" override="false"/>
<Parameter name="smtp.from.address" value="[email protected]" override="false"/>
<Parameter name="smtp.from.name" value="Site administrator" override="false"/>
<Parameter name="list.name" value="DEV" override="false"/>
<Parameter name="temporary.folder" value="/tmp" override="false"/>
<Parameter name="authentication.type" value="LDAP" override="false"/>
+1  A: 

You could use JNDI properties instead. I believe that Glassfish uses a jndi.properties file.

http://docs.sun.com/app/docs/doc/820-4336/gcpge?a=view

Kaleb Brasee
+1  A: 

In your app's web.xml, per JEE specs.

Here is tomcat's blurb about context.xml.

You can configure named values that will be made visible to the web application as servlet context initialization parameters by nesting elements inside this element. For example, you can create an initialization parameter like this:

<Context ...>   ...   
<Parameter name="companyName" value="My Company, 
 Incorporated" override="false"/>
</Context>

This is equivalent to the inclusion of the following element in the web application deployment descriptor (/WEB-INF/web.xml):

<context-param>   
 <param-name>companyName</param-name>  
 <param-value>My Company, Incorporated</param-value>
</context-param>
This works for parameters, but how about for setting up database connection pools?
corydoras
Connection pools are defined using the admin gui. But if you need your xml fix, its all in sun-web.xml.
Setting aside the fact I am quite offended you think I like XML. The point is that database connections should not have to be manually configured every time you deploy an application. With tomcat you just setup the config details and you can deploy to the server without having to screw around with GUI interfaces. Add to that the possibility that users playing with the admin interface may forget to do things like turn on UTF-8 support on the JDBC connection pool and its a recipe for disaster.
corydoras
A: 

Turns out the answer is there is no alternative to the section in tomcats context.xml.

It turns out that the element is a tomcat specific thing generally not supported by other app servers such as glassfish.

As far as I can tell there seems to be no simple/sensible alternative apart from manually configuring database resources through either GUI or command line interfaces.

corydoras
As unfortunate as it is, that's just how it works. Kinda like how at work we have an orion-application.xml file to configure things on Oracle Application Server.
R. Bemrose