The question no one can answer

We have a problem. Looking thru the forum I see that many others have posted about the same problem, but no one has gotten an answer. This is so basic to deplyment that I can't believe there is no answer. See

http://forum.java.sun.com/thread.jspa?forumID=51&threadID=750657

http://forum.java.sun.com/thread.jspa?forumID=51&threadID=521954

http://forum.java.sun.com/thread.jspa?forumID=51&threadID=680195

We develop under Tomcat, but sometimes need to deploy to WebSphere. As a part of deployment we need to modify a configuration file because under Tomcat we need to reference our datasource as java:comp/env/jdbc/theDataSource while in WebSphere it is just jdbc/theDataSource since it is defined as a WebSphere datasource.

Having to modify the config file in the war file is very undesirable and error-prone. We already had one production deployment failure due to it.

Is there some way in the app server we can define an alias or something so that the application can always reference the datasource in a consistent manner. This seems to be a very basic and important requirement for easy deployment.

In our case we are using Spring to get the datasource so we have no control over the code which gets the initial context, datasource, etc.

Does anyone have any recomendations on how to do this in a consistent and reliable manner.

Thanks,

-- Frank

[1430 byte] By [flawlora] at [2007-10-3 3:02:14]
# 1
You should make an ENC entry in your bean to link java:comp/env/... to the actual global resource.
dannyyatesa at 2007-7-14 20:51:59 > top of Java-index,Core,Core APIs...
# 2
Thanks for the quick reply.Could you elaborate furthuer? How about an example of such an entry and where does this go? -- Frank
flawlora at 2007-7-14 20:51:59 > top of Java-index,Core,Core APIs...
# 3

OK, it's been a while since I've hand-crafted J2EE deployment descriptors...

In your ejb-jar.xml, you define an <resource-ref> like this:

<resource-ref>

<res-ref-name>jdbc/blah</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

<description>

Some kind of description

</description>

</resource-ref>

Each bean (and some other things) has a "local" JNDI tree called the ENC (Environmental Naming Context). What this piece of XML does is make a name "java:comp/env/jdbc/blah" available to your bean. (Note the relationship between the name you declare in the XML and the name you use in the lookup).

All we've said so far is that this refers to a DataSource (there's a limit number of things you can point to like this... JMS and JDBC being two of them). Now we have to like this to an actual resource defined on the server.

To do this, you need to use the server-specific bean descriptor file. Refer to your server documentation for this. Normally, there's a stanza that looks something like this:

<resource-ref><!-- or res-ref -->

<res-ref-name>jdbc/blah</res-ref-name>

<jndi-name>/some/global/jndi/name</jndi-name>

</resource-ref>

Think of these like symlinks in Unix. The benefit is that you can refer to the ENC name (java:comp/env/...) in your code, and the guy who deploys to the app server can map that (via the server-specific descriptor) to an actual resource using the servers naming conventions.

dannyyatesa at 2007-7-14 20:51:59 > top of Java-index,Core,Core APIs...
# 4

Oh, and just to clarify on your cross-server question... you can package a WebSphere-specific descriptor AND a Tomcat-specific descriptor in the same war-file and you should be fine.

We have an application which I designed at work which was initially developed on JBoss, then deployed onto Borland Enterprise Server and the ported to WebLogic. It has deployment descriptors for all three in the EAR file, and the same EAR deploys and runs unaltered on all three app-servers.

App-server independant J2EE is possible, despite what many people say. You just have to make sure you stick to the specs.

dannyyatesa at 2007-7-14 20:51:59 > top of Java-index,Core,Core APIs...
# 5
Thanks, worked great.In my case I put the ref in web.xml.
flawlora at 2007-7-14 20:51:59 > top of Java-index,Core,Core APIs...
# 6
Sorry, it didn't occur to me that you were writing a webapp. Glad you've got it figured out.(So am I "no one" now?!)
dannyyatesa at 2007-7-14 20:51:59 > top of Java-index,Core,Core APIs...