Define class loader for web application with Liberty - spring-boot

I have an application Rest service it is a war I want to deploy it in Liberty profile.Currently I am packaging the app along with all spring jar inside war.
But we want to create a shared library and move all those jar's into shared lib and reference that shared library using class loader from application.
server.xml
<application location ="restapp-1.0.0-SNAPSHOT.war" context-root="/myrestapp/mytestapp">
<classloader commonLibraryRef="global"/>
</application>
<library id="global">
<fileset includes="*.jar" dir="${server.config.dir}/lib/global"></fileset>
</library>
Also I have placed all the jar dependencies under server/config/lib/global.
I am having below entries in my ibm-web-ext.xml which is in webapp/WEB-INF/
<web-ext
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd"
version="1.0">
<reload-interval value="3"/>
<context-root uri="/myrestapp/mytestapp" />
<enable-directory-browsing value="false"/>
<enable-file-serving value="true"/>
<enable-reloading value="true"/>
<enable-serving-servlets-by-class-name value="false" />
</web-ext>
Same config is working fine if I bundle all the jar's as part of WAR and place the war in dropins folder. But Sharedlibrary configuration is not working.

You can define a shared library for your application in WebSphere Liberty by putting the following configuration in the server.xml:
<library id="springLib">
<fileset dir="${server.config.dir}/libs/spring/" includes="*.jar"/>
</library>
<application location ="restService.war">
<classloader commonLibraryRef="springLib"/>
</application>
With this configuration, code in the restService.war will be able to load classes from the springLib shared library.
See also: Liberty: Shared Libraries

Related

Error executing CICS request while deploying app into IBM liberty Profile

I´ve got an app that works perfectly if I deploy it (in my local) into WAS. However, I´m getting the following exception connecting to CICS services if if deploy it into Liberty Profile (WebSphere Application Server 8.5.5.8/wlp-1.0.11.cl50820151201-1942) in IBM J9 VM, version pwa6470_27sr2fp10-20141218_02 (SR2 FP10)
:
com.ibm.connector2.cics.CICSUserInputException#a71e6144
[invalidProperties=<null>,errorCode=<null>,linkedException=<null>,
detailMessage=CTG9628E InteractionSpec passed to execute() not of type ECIInteractionSpec,
cause=com.ibm.connector2.cics.CICSUserInputException#a71e6144,stackTrace=<null>,
suppressedExceptions=[]]
However the IteractionSpec IS an instance of ECIInteractionSpec:
This is my server.xml, for what is worth:
<server description="new server">
<featureManager>
<feature>jsp-2.2</feature>
<feature>jpa-2.0</feature>
<feature>jaxrs-1.1</feature>
<feature>cdi-1.0</feature>
<feature>beanValidation-1.0</feature>
<feature>ejbLite-3.1</feature>
<feature>json-1.0</feature>
<feature>apiDiscovery-1.0</feature>
<feature>managedBeans-1.0</feature>
<feature>jca-1.6</feature>
<feature>jndi-1.0</feature>
<feature>javaMail-1.5</feature>
<feature>jaxws-2.2</feature>
<feature>localConnector-1.0</feature>
<feature>jms-1.1</feature>
<feature>servlet-3.1</feature>
</featureManager>
<variable name="SHARED_LIB_ROOT" value="C:\IBM\\IBM\liberty_jars"/>
<variable name="SHARED_LIB_CONFLU" value="C:\IBM\SHARED_LIB"/>
<resourceAdapter autoStart="true" id="eciResourceAdapter" location="${SHARED_LIB_CONFLU}/cicseci-9.1.rar">
<classloader apiTypeVisibility="spec, ibm-api, third-party"/>
</resourceAdapter>
<library apiTypeVisibility="spec, ibm-api, third-party" id="gneislibrary">
<folder dir="${SHARED_LIB_CONFLU}"/>
</library>
<!-- drivers lib -->
<!-- ORACLE -->
<library id="oracle-lib">
<fileset dir="${SHARED_LIB_ROOT}\drivers\oracle" includes="oracle-ojdbc6-11.2.0.3.0.jar"/>
</library>
<!-- DB2 -->
<library id="db2-lib">
<fileset dir="${SHARED_LIB_ROOT}\drivers\db2" includes="db2jcc.jar db2jcc_license_cisuz.jar"/>
</library>
<!-- To access this server from a remote client add a host attribute to
the following element, e.g. host="*" -->
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
<connectionFactory id="eciTest" jndiName="eis/CICSPWAS">
<properties.eciResourceAdapter TPNName="SCTG" connectionUrl="my_hostname" portNumber="my_port_number" tracelevel="3" userName="my_user_name"/>
</connectionFactory>
<!-- external libs -->
<library id="external-lib">
<fileset dir="${SHARED_LIB_ROOT}\external-lib" includes="*"/>
<folder dir="${SHARED_LIB_ROOT}\external-lib"/>
</library>
<quickStartSecurity userName="wasadmin" userPassword="123456"/>
<webApplication contextRoot="/myapp" id="oauth" location="myapp.war" name="myapp">
<classloader apiTypeVisibility="spec, ibm-api, third-party" classProviderRef="eciResourceAdapter" commonLibraryRef="gneislibrary" delegation="parentFirst"/>
</webApplication>
<keyStore location="${server.output.dir}/resources/security/key.jks"></keyStore>
</server>
The "CTG9628E InteractionSpec passed to execute() not of type ECIInteractionSpec" message is issued when the CICS TG RAR code checks whether the Interaction Spec passed an instance of the expected ECIInteractionSpec from application. This suggests that the application is not passing the expected ECIInteractionSpec. One possibility could be CICS TG RAR file used for compiling the application is different from version of CICS TG RAR files defined the WebSphere Liberty server profile.
Can you try downloading latest version of CICS TG RAR file from:
https://developer.ibm.com/cics/2016/03/11/cics-tg-sdks
Copy (after extracting) the CICS TG RAR file from /cicstgsdk/api/jee/runtime/managed/cicseci.rar to your application and recompile the application. Also use the same CICS TG RAR in your liberty profile and verify the scenario.
I fixed it. Thanks a lot guys for your help. The project got included transitive dependencies to very old versions of cicseci library. I excluded them. I don´t understand yet why it works perfectly on WAS and it fails in WLP.

IBM Liberty Profile Context Root Not Found

I've deployed a spring application to IBM Liberty Profile. Both of the server and the application starts without problem, but when I would like to reach the application the browser says "Context Root Not Found"
I've configured the application in several ways in the server.xml
<application location="d:/Work/Installed Liberty Applications/OFRAdminEAR/OFRAdmin.ear"
name="OFRAdmin"
security-role="false"
id="OFRAdmin"
type="ear">
<classloader apiTypeVisibility="spec,ibm-api,api" privateLibraryRef="WebspherePlugins, OFRAdminsSharedLibrary"/>
</application>
<enterpriseApplication location="d:/Work/Installed Liberty Applications/OFRAdminEAR/OFRAdmin.ear"
id="OFRAdmin"
name="OFRAdmin"
security-role="false"
type="ear">
<classloader privateLibraryRef="WebspherePlugins, OFRAdminsSharedLibrary" />
</enterpriseApplication>
<webApplication location="d:/Work/Installed Liberty Applications/OFRAdminEAR/OFRAdmin.ear"
id="OFRAdmin"
name="OFRAdmin"
security-role="false"
type="war">
<classloader privateLibraryRef="WebspherePlugins, OFRAdminsSharedLibrary" />
</webApplication>
The application packed into an ear file, which contains a WAR file and META-INF folder with the application.xml. The application.xml looks like this.
<application-name>OFRAdmin</application-name>
<display-name>OFRAdmin</display-name>
<module>
<web>
<web-uri>OFRAdmin.war</web-uri>
<context-root>OFRAdmin</context-root>
</web>
</module>
</application>
What I missed? Where should I set the context root of the application? Can anybody help me?

CWWKL0008W Warning seems wrong based on what I can configure in server.xml

I am getting a warning when starting my v17.0.0.4 Liberty server for a shared library and war not having the same class loading specifications:
[WARNING ] CWWKL0008W: Application [myRESTServices#myRESTServices-1.0.0-SNAPSHOT.war] is incompatible with the common class loader for library [myJARS] because they have inconsistent API visibility configurations. Library [myJARS] is configured with [[spec, ibm-api, api, stable]] and application [myRESTServices#myRESTServices-1.0.0-SNAPSHOT.war] is configured with [[spec, ibm-api, api, third-party]].
However, the server.xml defines both with the same set:
<library apiTypeVisibility="spec,ibm-api,api,third-party" description="My Shared Libraries from the myJARS directory" id="myJARS" name="myJARS">
<fileset dir="/csnext/myJARS" id="myJARS" includes="*.jar" scanInterval="30s"/>
</library>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<webApplication id="myRESTServices" location="myRESTServices-1.0.0-SNAPSHOT.war" name="myRESTServices">
<classloader apiTypeVisibility="spec,ibm-api,api,third-party">
<commonLibrary id="myJARS" name="myJARS" >
<fileset id="myJARS" dir="/csnext/myJARS" includes="*.jar"></fileset>
</commonLibrary>
</classloader>
</webApplication>
Your application is not using the library that is defined with apiTypeVisibility, it is using a separate copy of the library definition. I think you want this for the application configuration:
<webApplication id="myRESTServices" location="myRESTServices-1.0.0-SNAPSHOT.war" name="myRESTServices">
<classloader apiTypeVisibility="spec,ibm-api,api,third-party" commonLibraryRef="myJARS"/>
</webApplication>

Unable to use JCA CICS resource with IBM WebSphere Application Server Liberty Profile

I'm trying to setup WLP for an existing EAR application.
This setup works fine with WAS 9 traditional.
The problem is the JCA CICS Resource Adapter call.
The server.xml :
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>javaee-7.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint"
host="*"
httpPort="9080"
httpsPort="9443" />
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<library id="sharedLibs">
<fileset dir="/work/sharedlibs" includes="*.jar"/>
<folder dir="/work" />
</library>
<resourceAdapter
autoStart="true"
id="eciResourceAdapter"
location="/work/cicseci.rar">
</resourceAdapter>
<connectionFactory id="CTGDV06" jndiName="jca/CTGDV06" >
<properties.eciResourceAdapter.javax.resource.cci.ConnectionFactory
connectionUrl="tcp://*******"
serverName="*******"
userName="*******"
portNumber="2006"
/>
</connectionFactory>
<application type="ear" id="app" location="app.ear" name="app">
<classloader
commonLibraryRef="sharedLibs"
classProviderRef="eciResourceAdapter" />
</application>
</server>
in ibm-web-bnd.xml :
<resource-ref name="cicsjca" binding-name="jca/CTGDV06"></resource-ref>
in web.xml :
<resource-ref id="ResourceRef_Cics_Jca">
<description>Acces CICS</description>
<res-ref-name>cicsjca</res-ref-name>
<res-type>javax.resource.cci.ConnectionFactory</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
Startup is Ok, but access to JCA fail with :
java.lang.Exception: Lookup for java:comp/env/cicsjca failed. Exception: javax.naming.NamingException: CWNEN1001E: The object referenced by the java:comp/env/cicsjca JNDI name could not be instantiated. If the reference name maps to a JNDI name in the deployment descriptor bindings for the application performing the JNDI lookup, make sure that the JNDI name mapping in the deployment descriptor binding is correct. If the JNDI name mapping is correct, make sure the target resource can be resolved with the specified name relative to the default initial context.
[Root exception is com.ibm.wsspi.injectionengine.InjectionException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/cicsjca reference. The exception message was: CWNEN1003E: The server was unable to find the jca/CTGDV06 binding with the javax.resource.cci.ConnectionFactory type for the java:comp/env/cicsjca reference.]
I don't understand what's wrong with this setup, any help would be apreciated !
The correct configuration depends on how many connection factory implementations are provided by the resource adapter.
If the resource adapter provides only a single connection factory (which is commonly the case for many resource adapters), then configuration would be:
<connectionFactory id="CTGDV06" jndiName="jca/CTGDV06" >
<properties.eciResourceAdapter
connectionUrl="tcp://*******"
serverName="*******"
userName="*******"
portNumber="2006"
/>
</connectionFactory>
Full detail on how to specify configuration for JCA resource adapters in Liberty can be found here in the knowledge center.

WebSphere Liberty Profile: Context Root Not Found

I can't seem to get this working locally, even though the same WAR works on a remote server. When I go to visit my application locally, I get the "Context Root Not Found" error. The Liberty profile version is 8.5.5.5.
Here are the relevant files:
server.xml
<?xml version="1.0" encoding="UTF-8"?>
<server description="tlc server">
<!-- Enable features -->
<featureManager>
<feature>jsp-2.2</feature>
<feature>ssl-1.0</feature>
<feature>localConnector-1.0</feature>
<feature>restConnector-1.0</feature>
<feature>json-1.0</feature>
<feature>jaxrs-1.1</feature>
<feature>servlet-3.0</feature>
<feature>jpa-2.0</feature>
<feature>beanValidation-1.0</feature>
<feature>jndi-1.0</feature>
<feature>jdbc-4.0</feature>
<feature>monitor-1.0</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443" virtualHost="default_host" />
<jdbcDriver id="DerbyJDBCDriver">
<library name="DerbyLib">
<fileset dir="C:\tools\servers\wlp\lib" includes="derbyclient-10.6.1.0.jar" />
</library>
</jdbcDriver>
<dataSource jndiName="jdbc/TLCDataSource" id="derbyDataSource" jdbcDriverRef="DerbyJDBCDriver">
<properties.derby.client databaseName="TLC" password="APP" user="APP" />
</dataSource>
<applicationMonitor updateTrigger="mbean" />
<application id="TLC_war" context-root="/TLC" location="C:\Users\nd26434\gitrepos\tlc\target\TLC-1.0.0-SNAPSHOT.war" name="TLC_war" type="war">
<classloader delegation="parentLast">
<privateLibrary>
<fileset dir="C:\tools\servers\wlp\lib" includes="aspectjweaver-1.8.0.jar" />
</privateLibrary>
</classloader>
</application>
</server>
message.log
[3/18/15 20:19:54:789 EDT] 0000001b com.ibm.ws.app.manager.AppMessageHelper A CWWKZ0022W: Application TLC_war has not started in 30.018 seconds.
[3/18/15 20:20:03:174 EDT] 0000001f com.ibm.ws.webcontainer.osgi.webapp.WebGroup I SRVE0169I: Loading Web Module: TLC-1.0.0-SNAPSHOT.
[3/18/15 20:20:03:175 EDT] 0000001f com.ibm.ws.webcontainer I SRVE0250I: Web Module TLC-1.0.0-SNAPSHOT has been bound to tlc_host.
ibm-web-bnd.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-bnd xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
version="1.0">
<virtual-host name="tlc_host"/>
<resource-ref name="jdbc/TLCDataSource"
binding-name="jdbc/TLCDataSource" />
</web-bnd>
ibm-web-ext.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-ext
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd"
version="1.0">
<reload-interval value="3"/>
<context-root uri="TLC" />
<enable-directory-browsing value="false"/>
<enable-file-serving value="true"/>
<enable-reloading value="true"/>
<enable-serving-servlets-by-class-name value="false" />
</web-ext>
Remove <virtual-host name="tlc_host"/> from your ibm-web-ext.xml file. As you dont have tlc_host, but default_host.
Context Root Not found is caused due to issue in one of the config files.
In my case, web.xml had an unclosed comment due to which the war was not built correctly.
This resulted in EAR file not updating.
Solution:
Compare you web.xml with previous versions to see what changed.
Add war to the server instead of the ear file to see the error. (If Running on Liberty Server)

Resources