Page History
...
Through the WSO2 Application Server's runtime environment, you can control class loading per server or application. The default runtimes are sufficient for most users, but you can also define your own runtimes. There are four default run-times 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 in the CXF environment's lib directory.
- Javaee Environment: This consists of the Javaee runtime.
The subsequent sections explain how to place your external dependencies in a running Carbon server, to configure class loading per application or server.
Table of Contents maxLevel 3 minLevel 3
Configuring Class Loading
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: <PRODUCT_HOME>/repository/deployment/server/webapps/SampleApp
.
Info |
---|
The Carbon runtime is the default runtime that is in effect. If you want to use the runtime environments other than Carbon, provide the webapp-classloading.xml file with the correct configurations. Otherwise, the application will be deployed in the default Carbon runtime environment. |
The webapp webapp-classloading.xml
file takes the following format:
Code Block | ||
---|---|---|
| ||
<Classloading xmlns="http://wso2.org/projects/as/classloading"> <Environments>{Runtime Environment Names} </Environments> </Classloading> |
Shown below is the the
webapp-classloading.xml
file file configuration to specify CXF as the runtime environment:Code Block language html/xml <Classloading xmlns="http://wso2.org/projects/as/classloading"> <Environments>CXF</Environments> </Classloading>
Shown below is the configuration to specify 'Javaee' as the runtime environment.
Code Block language html/xml <Classloading xmlns="http://wso2.org/projects/as/classloading"> <Environments>Javaee</Environments> </Classloading>
You might want to access some Carbon features in a CXF application. To achieve this, specify a comma-separated list of environments in in
webapp-classloading.xml
file file. The following example specifies both CXF and Carbon as the runtime environments:Code Block language html/xml <Classloading xmlns="http://wso2.org/projects/as/classloading"> <Environments>Spring,Carbon</Environments> </Classloading>
...
You can share dependencies with a number of applications without packaging them with each and every one of them. To do this, place the common dependencies in the following directories depending on your environment.
- In Tomcat Environment -
<PRODUCT_HOME>/lib/runtimes/ext
- In Carbon Environment -
<PRODUCT_HOME>/repository/components/lib
- In CXF or any Custom Environment – Use the environment's s
lib
directory directory.
For example:
<PRODUCT_HOME>/lib/runtimes/cxf
Info |
---|
Practice caution when placing dependency files in Tomcat environment's If there are such incompatible dependencies, the recommended best practice is to package them in the web application in Tomcat environment itself. Libraries that are only used by a particular web application can be put into the |
...
To define custom runtime environments, add a new element as as <ExclusiveEnvironments>
in in the <PRODUCT <PRODUCT_HOME>/repository/conf/tomcat/webapp-classloading-environments.xml
file file.
To define a custom runtime environment for Spring.
Modify the the
webapp-classloading-environments.xml
file with the following entries.Code Block language html/xml <ExclusiveEnvironments> <ExclusiveEnvironment> <Name>Spring</Name> <Classpath>${carbon.home}/lib/runtimes/spring/*.jar;${carbon.home}/lib/runtimes/spring/</Classpath> </ExclusiveEnvironment> </ExclusiveEnvironments>
- Next, create and copy of the related Spring dependencies in the the
<PRODUCT_HOME>/lib/runtimes/spring
directory directory. Add the following entries to the the
webapp-classloading.xml
file file of each web application, to use them in in the Spring runtime environment defined above.Code Block language html/xml <Classloading xmlns="http://wso2.org/projects/as/classloading"> <Environments>Spring,Carbon</Environments> </Classloading>
Info |
---|
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.
If a web application consumes both of the above environments, the following problems will arise:
|
...
Upgrade the CXF runtime environment : You can replace the existing existing
CXF/Spring
dependent dependent JARs in the the<PRODUCT_HOME>/lib/runtimes/cxf
directory directory, with new newCXF/Spring
JARs JARs.Instead of upgrading server-level CXF dependencies, you can package all the required JARs in the the
Web-INF/lib
directory directory of the web application and deploy that in the Tomcat runtime environment.
If you want to add optional optional CXF/Spring
JARs JARs, copy them to the <PRODUCT_HOME>/lib/runtimes/cxf
directory directory after ensuring that they are compatible with the existing JARs.
...