Access third-party APIs from a Java EE application
By default, Java EE applications do not have access to the third-party APIs available in Liberty. To enable this access, the application must be configured in server.xml, or an included file.
In the following example, an application called Scholar needs access to the third-party APIs available in Liberty. The application also uses a common library called Alexandria. This library is located in...
-
${server.config.dir}/mylib/Alexandria
Avoid trouble: Third-party APIs might not remain compatible after an upgrade.
See Liberty externals support.
Steps
- Configure class loading for the application so that the application can access the third-party APIs.
Values for the apiTypeVisibility attribute...
spec Public specification APIs available for both compile and run time ibm-api APIs available in Liberty. api Public APIs available for both compile and run time stable Stable third party specification APIs available by default for both compile and run time. Including third-party in the apiTypeVisibility attribute of the classloader element makes third-party APIs available. third-party Common usage for the prefix, +third-party, results in "spec, ibm-api, api, stable, third-party". The prefix, -api, results in "spec, ibm-api, stable". In server.xml, or an included file, configure the API type visibility...
<application id="scholar" name="Scholar" type="ear" location="scholar.ear"> <classloader apiTypeVisibility="spec, ibm-api, stable, third-party" commonLibraryRef="Alexandria" /> </application>
If a prefix of + or - is added to API types, those API types are added or removed, respectively, from the default set of API types. The +third-party prefix results in spec, ibm-api, api, stable, third-party. The -api prefix results in spec, ibm-api, stable.
In server.xml, or an included file, configure the API type visibility by adding the following code:
<application id="scholar" name="Scholar" type="ear" location="scholar.ear"> <classloader apiTypeVisibility="+third-party, -api" commonLibraryRef="Alexandria" /> </application>
- If the application uses any common libraries, set those libraries to use the same API type visibility setting.
In server.xml, or an included file, add...
<library id="Alexandria" apiTypeVisibility="spec, ibm-api, stable, third-party" > <fileset dir="${server.config.dir}/mylib/Alexandria" includes="*.jar" scanInterval="5s" /> </library>
Parent topic: Configure class loaders and libraries for Java EE applications
Related tasks
- Use a Java library with a Java EE application
- Sharing a library across multiple Java EE applications
- Providing global libraries for all Java EE applications
- Remove access to third-party APIs for a Java EE application
- Overriding a provided API with an alternative version
- Configure the web module class loader for an enterprise application
- Class loader configuration