Access stand-alone resource adapters from Java EE applications
We can access stand-alone resource adapters from Java EE applications.
Stand-alone resource adapter classes and resources can be shared across multiple Java EE applications. By default, Java EE applications have access to JCA spec API but do not have access to the vendor classes and resources of stand-alone resource adapters. A prerequisite of enabling this access is that both the resource adapter and the application must be configured in the server configuration.
In the following example, an application called Scholar and an application called Student are running on a server called Academy. Both applications need access to a resource adapter called Socrates16, which is provided in the socrates.rar file located in the C:/adapters/version-1.6 directory.
- Configure the stand-alone resource adapter.
In server.xml, configure the stand-alone resource adapter by adding the following code:
<resourceAdapter id="Socrates16" location="C:/adapters/version-1.6/socrates.rar" />
- Reference the resource adapter from the applications so that both applications can access the classes and resources provided in the resource adapter module.
In server.xml, set the classProviderRef attribute to the ID of the resource adapter within the class loading configurations of the applications by adding the following code:
<application id="scholar" name="Scholar" type="ear" location="scholar.ear"> <classloader classProviderRef="Socrates16" /> </application> <application id="student" name="Student" type="ear" location="student.ear"> <classloader classProviderRef="Socrates16" /> </application>
- Optional: Configure the class loading of the stand-alone resource adapter to access third-party APIs.
By default, neither resource adapters nor Java applications can access third-party APIs. Whenever the class loading configuration of an application requires access to third-party APIs and the application requires access to a stand-alone resource adapter, configure the class loading of the resource adapter to also access third-party APIs.
In server.xml, configure the apiTypeVisibility attribute of the class loading configuration of the resource adapter to access third-party APIs by adding the following code:
<resourceAdapter id="Socrates16" location="C:/adapters/version-1.6/socrates.rar"> <classloader apiTypeVisibility="spec, ibm-api, api, third-party" /> <resourceAdapter/> <application id="scholar" name="Scholar" type="ear" location="scholar.ear"> <classloader classProviderRef="Socrates16" apiTypeVisibility="spec, ibm-api, api, third-party" /> </application> <application id="student" name="Student" type="ear"location="student.ear"> <classloader classProviderRef="Socrates16" apiTypeVisibility="spec, ibm-api, api, third-party" /> </application>
Parent topic:
Overview of JCA configuration elements