Skip to main content

Web application configuration

7 replies [Last post]
hadrabap
Offline
Joined: 2006-01-31

Hi all,

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)?

Thank you very much for your replies.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
hadrabap
Offline
Joined: 2006-01-31

So,

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

The administrator do the following:
- prepares database (using provided script)
- creates database pools
- creates database resources (this also makes JNDI entries)
- creates mail sessions
- writes sun-web.xml which maps created JNDI names (mail and JDBC resources) to the provided hardcoded names
- deploys the WAR file with his own (custom) sun-web.xml file

Soooooo, I think, this is the right solution. I think, this is a little bit obscure, but functional.

Any comments or yours experiences? I'm new to Java EE unfortunatly:-(

At the end:
Many many thanks for all, who helped me. Thank you!

PETR

vbkraemer
Offline
Joined: 2003-09-03

actually...

You can package a sun-web.xml in the war file for deployment... Then an admin/deployer would only need to change it (write a new one), IF the names you selected for your app were already in use...

The admin/deployer would only need to create the pools/sources/sessions and deploy...

Since the sun-web.xml file is not read by other servers, its present doesn't interfer with deploying teh war file onto other servers like Tomcat.

vbk

hadrabap
Offline
Joined: 2006-01-31

Yes, yes, yes!

All thanks to You!

> sun-web.xml is not read by other servers

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!

Have a nice day!

PETR

km105526
Offline
Joined: 2005-04-04

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".

Hope this helps.

Regards,
Kedar

hadrabap
Offline
Joined: 2006-01-31

Hello Kedar,

thanks for your reply.

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/webapp
this/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?

Thank you very much for your explanation.

PETR

vbkraemer
Offline
Joined: 2003-09-03

The per-application configuration goes into the sun-web.xml file. You can read about that in this document: http://docs.sun.com/app/docs/doc/819-3660/6n5s7klpg?a=view

I am not too sure about the concept you are asking about in your second paragraph, so I won't answer that one.

The best way to deliver that app is as a war file....

If clients need to deploy an archive without repackaging it, they can use the --deploymentplan option of asadmin's deploy commmand. The commmand is documented in this document: http://docs.sun.com/app/docs/doc/819-3662/6n5s9hmvk?a=view

hadrabap
Offline
Joined: 2006-01-31

Thank you very much for your sources! I'll read more about --deploymentplan. It seems to solve my problem...