4

I have a JDBC datasource defined in WebSphere named 'jdbc/dataSource1'.
In my application based on Spring i want to obtain the datasource using jndi lookup, but by another name, like 'jdbc/dataSource2'.
To achieve this i created ibm-web-bnd.xml file, in which i defined the linkage as follows:

<resource-ref binding-name="jdbc/dataSource2" name="jdbc/dataSource1"/>

Also i defined the datasource in the web.xml file as follows:

<resource-ref>
    <description>some awesome datasource</description>
    <res-ref-name>jdbc/dataSource2</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

The solution works only while deploying using IBM Web Console. When i try to deploy it using custom jython script using wsadmin tool, i get the following error:

ADMA0007E: A Validation error occurred in task Mapping resource references to re
sources. The Java Naming and Directory Interface (JNDI) name is not specified f
or reference binding jdbc/dataSource2 in module <application_name>.war"

In wsadmin script i use AdminApp.install(path_to_ear, options), where options variable contain only options regarding virtual hosts mapping.

So the question is what should i do, so the WebSphere will get the datasource mapping options from ibm-web-bnd.xml file?

Burkhard
  • 14,596
  • 22
  • 87
  • 108
crew4ok
  • 195
  • 1
  • 3
  • 10

2 Answers2

3

You'll need to add MapResEnvRefToRes option to AdminApp.install call to map resource reference to resource. Check this link for more:

http://www-01.ibm.com/support/knowledgecenter/api/content/SSEQTP_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/rxml_taskoptions.html#rxml_taskoptions__cmd56

The quickest way to get it done is to enable "command assistance logging" and proceed with installation via AdminConsole. In the command assistance log you'll find the exact AdminApp.install syntax for your deployment and mapping of resource references to actual resources.

Ad mode (I'm contributing to OSS project mentioned below)

If you consider more sophisticated automation project (not just one application install), then you may find WDR library useful. With WDR you can export all your application settings into a manifest file, which includes MapResEnvRefToRes settings. Then you can deploy the application based on that manifest.

Marcin Płonka
  • 2,840
  • 1
  • 17
  • 17
  • 1
    I considered Map* options as a workaround, since doesn't it seems to be a duplication of datasource definition? I defined it already in my web.xml and in ibm-web-bnd.xml files, can't WebSphere figure out the datasources mapping without me specifying it twice (i mean in ibm-web-bnd.xml AND in deployment script)? – crew4ok Aug 30 '14 at 18:58
  • 1
    btw, the library you mentioned seems really useful to me, but as i can get it consists of many files (which is opposite to a single file in wsadminlib.py, for instance) and i try to leave the deployment script as small as possible because it's supposed to be copied over ssh on many WS instances. – crew4ok Aug 30 '14 at 19:04
3

Try to call AppAdmin.install(path_to_ear) without options. Then options are read from the bnd file and there is no validation error. And ensure that ibm-web-bnd.xml file is in the ear file.

UPDATE

Ok I've noticed your error. In your binding file it should be the other way around:

<resource-ref name="jdbc/MyRef" binding-name="jdbc/JNDI" />

so in your case name is datasource2 and binding is jndiname - so datasource1:

<resource-ref binding-name="jdbc/dataSource1" name="jdbc/dataSource2"/>
Gas
  • 17,601
  • 4
  • 46
  • 93
  • 1
    I tried, i gave me the error i put in the question. As for `ibm-web-bnd.xml` - in my application it located in war file inside an ear file. Am i doing it right? :) – crew4ok Aug 30 '14 at 19:38
  • It should be in WEB-INF folder, just beside your web.xml – Gas Aug 30 '14 at 19:42
  • 1
    @crew4ok you have error in binding file, see my updated answer. – Gas Aug 30 '14 at 19:48
  • 1
    damn, it seems to be working... i'm sorry for asking such stupid questions and wasting your time guys...( this file is a part of a legacy codebase, so i thought it should be okay. anyway, thank you for your answer! – crew4ok Aug 31 '14 at 05:59