WSO2 AS leverages a concept called runtime environments to separately maintain different runtimes for loading the relevant classes for your web applications. The WSO2 web application management feature provides the capability to load classes from different locations to your applications.
Most web applications that are deployed in production environments depend on external, third-party libraries for different functionality. Through the WSO2 Application Server's runtime environment, you can control class loading per server or application. The following runtimes that are available with WSO2 AS are sufficient for most users, but you can also define your own runtimes. There are four default runtime environments available in AS 5.3.0, which are as follows:
- Tomcat Environment: This is the minimal runtime, which is identical to a pure Tomcat runtime. It only has Tomcat, Servlet, JSP, EL and JSTL available in the server-level classpath. If you want additional JARs, you should package them with the web application or place them in the Tomcat environment's extension directory.
- Carbon Environment: This consists of both the Tomcat environment and the WSO2 Carbon runtime. It does not provide CXF or Spring dependencies. If you want additional JARs, you should package them with the web application or place them in the WSO2 Carbon environment's extension directory.
- CXF Environment: This consists of the Tomcat environment, CXF and Spring. It does not provide the WSO2 Carbon runtime. If you want additional JARs, you should package them with the web application or place them in the CXF environment's lib directory.
Javaee Environment: This consists of the Javaee runtime and the WSO2 Carbon runtime. If you want additional JARs, you should package them with the web application or place them in the Javaee environment's
See the following topics for more information:
Setting up the runtime environment
To configure class loading, you should add the class loading configuration in a file named
webapp-classloading.xml and place it in the META-INF directory of a web application. All the artifacts related to a web application are saved in the following directory:
<PRODUCT_HOME>/repository/deployment/server/<Web_Application_Type>/<Web_Application_Name>. For example:
webapp-classloading.xmlfile with the correct configurations. Otherwise, the application will be deployed in the default Carbon runtime environment.
webapp-classloading.xml file takes the following format:
Shown below is the
webapp-classloading.xmlfile configuration to specify CXF as the runtime environment:
You might want to access some Carbon features in a CXF application. To achieve this, specify a comma-separated list of environments in
webapp-classloading.xmlfile. The following example specifies both CXF and Carbon as the runtime environments:
From AS 5.3.0 onwards, Java EE 6 Web Profile support is available as a feature, which allows you to enable the Javaee runtime environment, in addition to Tomcat, Carbon and CXF runtime environments. See the topic on enabling Java EE 6 Web Profile for step-by-step instructions on configuring the Java EE runtime.
Extending the runtime environments
This section explains how to place your external dependencies in a running server. This allows you to share dependencies with a number of applications without packaging them with each and every application. To do this, place the common dependencies in the relevant directories given below.
- In Tomcat Environment -
- In Carbon Environment -
- In CXF, Javaee or any Custom Environment – Use the environment's
libdirectory. For example:
Practice caution when placing dependency files in Tomcat environment's
ext directory as those dependencies will be visible to all other environments. For example, if you place incompatible Spring dependencies in the
<PRODUCT_HOME>/lib/runtimes/ext directory, it can cause problems with the existing Spring dependencies in the CXF runtime environment.
If there are such incompatible dependencies, the recommended best practice is to package them with the web application in the Tomcat environment itself. Libraries that are only used by a particular web application can be put into the
Adding Custom Runtime Environments
To define a custom runtime environment for Spring:
webapp-classloading-environments.xmlfile with the following entries.
- Next, create and copy of the related Spring dependencies in the
Add the following entries to the
webapp-classloading.xmlfile of each web application so that they can be used in the Spring runtime environment defined above.
Note that adding custom runtime environments to your system without studying their impact can cause unfavorable results. For example, assume an Application Server (AS) instance contains the following configurations.
CXF (runtime provided by AS) contains CXF 2.7.5 and Spring 3.0.7 dependencies.
Spring (custom runtime) contains Spring 3.2.1 dependencies.
If a web application consumes both of the above environments, the following problems will arise:
The web application's classpath contains dependencies from two Spring versions as 3.0.7 and 3.2.0. The Spring project does not recommend this as it will cause several classloading issues.
CXF 2.7.5 itself uses Spring 3.0.7. It is possible that a particular CXF version is not properly tested for compliance with another version of Spring. You should study the CXF project recommendations to find a suitable Spring version.
Upgrading Existing Runtime Environments
The CXF runtime environment comes by default with core CXF 2.7.5 and core Spring 3.0.7 dependencies. If you want to upgrade to a different CXF version, there are two recommendations:
Upgrade the CXF runtime environment : You can replace the existing
CXF/Springdependent JARs in the
<PRODUCT_HOME>/lib/runtimes/cxfdirectory with new
Instead of upgrading server-level CXF dependencies, you can package all the required JARs in the
Web-INF/libdirectory of the web application and deploy that in the Tomcat runtime environment.
If you want to add optional
CXF/Spring JARs, copy them to the
<PRODUCT_HOME>/lib/runtimes/cxf directory after ensuring that they are compatible with the existing JARs.
Class loading pattern for web applications is always child-first and this can not be changed. Therefore, location 2 is always given the highest priority when the same library exists in both locations.