Web application configuration

You are here:

I'm developing a web application currently under Tomcat, but I found it works very very good under GlassFish. So, I decided to support glassfish too.

And I have some quetions:

Under tomcat, I have the admin web-app. I can manage datasources, environment properties for each web application. How can I achive this under glassfish? There is in the admin console only _global_ datasources, pools, properties...

The second question is concept-like: No, I have the datasource names hardwired inside the web application. What's the right solution to extract these (java.lang.)Strings out of the sources? I read something about new features under javaee5 (annotated JNDI resources or something like this).

What are the best steps to deliver application to the client? What must client usually do to successfuly deploy my web application (without repacking the .war file)?

Reply viewing options

I asked google for more informations about this question, here is my result I found:

I write a web application which uses Oracle database and mail session.

So, I must provide the following to the client's adminitrator:
- the WAR file
- database scheme initialization script
- all the JNDI datasource names hardcoded in my application
- all the mail session JNDI names hardcoded in my application

Yeah, I'm using this "feature". My web app is designed to run under Tomcat 5.5 and Glassfish. Tomcat "needs" META-INF/context.xml and Glassfish ignores this file; on the other side, Glassfish uses WEB-INF/sun-web.xml which is ignored by Tomcat! I find this feature great, elegant!

Much similar to the Tomcat Management Application(actually rather better), we have our admin console. Once the GlassFish is installed and the server is started using the asadmin start-domain command, the admin console which is basically a neat system application, is available at http://localhost:4848 if you chose defaults.

Look for the "Resources" node on the left hand side. Click on the triangle icon next to it and you'll see a new suite of probabilities that you can explore with various kinds of resources and connection pools.

Now coming to the so-called "mapping". Once the administrator creates the resources and pools, they are essentially global, all the deployed web applications can see them and more importantly look them up from the standard JNDI lookup. The only thing now required is to "map" a resource from a per application context to global JNDI tree. This is achieved by the sun-web.xml mapping for a resource reference. Look for resource-ref element in your app's sun-web.xml. This has a jndi-name which is the "same" as the one that you provide while creating the jdbc-resource on the admin screens.

A jdbc resource is usually backed by a connection pool and GlassFish has a sophisticated lazily initialzed connection pooling infrastructure.

BTW, what Tomcat lacks is "complete" CLI/scripting support that GlassFish enjoys. All that has said above is available in GlassFish as a rich set of commands. Please refer to "glassfish/bin/asadmin --help | more".

If I understand it: The sun-web.xml do the same as the META-INF/context.xml. At least the tags and their interpretation is the same.

So, I write an application and tell the administrator that my application uses data source under "jdbc/myDatasource". And the administrator creates pool, the JDBC resource and writes the sun-web.xml?

Example:this/uses/webappthis/is/global/resource

So: the "this/uses/webapp" is the lookup string used by the application (hardcoded string); and "this/is/global/resource" is global resource created in the admin console. So, I must tell the administrator: Map global resource to the "this/uses/webapp". Am I right?

Under Tomcat, when I deploy my application, I can use the admin application to create this mappings and/or create resources for this application only. So---I don't need to write context.xml by hand. Is something like this under Glassfish or I must create/modify sun-web.xml by hand?