2

I have deployed two ears and to one of them i do not have access. There is a file application-web-bnd.xml where is reference to datasource

In my server.xml file i have defined datasource

 <application id="MyCustomApp.war" location="F:\programming\source\MyCustomApp\target\MyCustomApp" name="MyCustomApp" type="war">
    <application-bnd>
      <security-role name="admin">
        <special-subject type="ALL_AUTHENTICATED_USERS" />
      </security-role>
      <data-source binding-name="jdbc/Sample" name="java:comp/env/jdbc/db" />
    </application-bnd>
  </application>

  <dataSource id="Sample" jndiName="jdbc/Sample" type="javax.sql.DataSource">
    <jdbcDriver>
      <library name="JdbcJarFiles">
        <fileset dir="${shared.resource.dir}" includes="db2jcc4.jar, db2jcc_license_cisuz.jar, db2jcc_license_cu.jar, pdq.jar, pdqmgmt.jar" />
        <folder dir="${shared.resource.dir}" />
      </library>
    </jdbcDriver>
  </dataSource>

In code in ear where i do not have access there is initialContext java:comp/env/jdbc/db.

Reference to data source exists but datasource does not exists. I do not have access to web.xml for create reference . I do not have ide how override it.

Could You help ?

My ear looks that:

 <module>
    <ejb>PRE-BF.jar</ejb>
  </module>
  <module>
    <web>
      <web-uri>PRE-WS.war</web-uri>
      <context-root>/PRE-WS</context-root>
    </web>
  </module>
  <module>
    <web>
      <web-uri>PRE-RS.war</web-uri>
      <context-root>/PRE-RS</context-root>
    </web>
  </module>
  <module>
    <web>
      <web-uri>PRE-PF.war</web-uri>
      <context-root>/PRE-PF</context-root>
    </web>
  </module>
darkstar
  • 21
  • 6

1 Answers1

1

You can override bindings in server configuration as follows. (This will require having your application defined in server configuration rather than dropins).

<application location="MyApp.war">
  <web-bnd moduleName="MyApp">
    <resource-ref name="jdbc/Sample" binding-name="java:comp/env/jdbc/db"/>
  </web-bnd>
</application>
njr
  • 3,399
  • 9
  • 7
  • The example had a mismatch between application-bnd and web-bnd because I was misreading application-web-bnd.xml as application bindings, vs web module bindings. I updated it for web-bnd – njr Oct 17 '19 at 21:29
  • Thank You. I did not know that we can do that. Where is that knowledge ?;) In home i have created two war apps to test but in company i have two ears . Inside ear i have 3 wars. Still i should use web-bnd tag ? – darkstar Oct 18 '19 at 07:04
  • I assume that i should use tag enterpriseApplication in server.xml but i do not know how to configure wars in that ear to pass datasource reference. – darkstar Oct 18 '19 at 07:27
  • I really i do not know how to override resources in ear -> wars and jar. I do not know how to match it. I tried allot of combinations. I have never seen in java:comp/env/jdbc/somekindofsource. Maybe i need to create some custom factory ? Does exist some example ? – darkstar Oct 18 '19 at 14:03
  • For .ear files, it is fine to use either `` or ``. Given that you have multiple modules, you will need to ensure that a `` entry with the corresponding `moduleName` is specified for each of the web modules where you want to override the resource reference. And likewise with `ejb-jar-bnd` and corresponding `moduleName` for EJB modules. It can be a bit tricky to get the syntax right. I tried out an override of a resource reference in a web module in this manner and it worked fine for me once I got the module name correct. – njr Oct 22 '19 at 15:04
  • Here is a link to knowledge center documentation listing the syntax for specifying `` or `` and so forth under ``. You'll need to scroll or search for these sub-elements, because the list of config options available for application is quite lengthy, https://www.ibm.com/support/knowledgecenter/en/SSAW57_liberty/com.ibm.websphere.liberty.autogen.nd.doc/ae/rwlp_config_application.html – njr Oct 22 '19 at 15:07