Tuesday, April 19, 2011

Endorsed Directory Mechanism

This mechanism in java is used when one version of a jar is being loaded from the boot strap class loader where as you need to load some other version of the same jar which is available in your lib folder.

For example the error can be like this:

20:21:06,667 ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cxf.wsdl.WSDLManager' defined in class path resource [META-INF/cxf/cxf.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.apache.cxf.wsdl11.WSDLManagerImpl]: Constructor threw exception; nested exception is java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/C:/Alfresco/tomcat/webapps/alfresco/WEB-INF/lib/jaxb-impl-2.1.7.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.1 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.5.0/docs/guide/standards/)

Here jaxb-impl2.0 is loaded even though you are having the verion 2.1 in your lib.

At this moment we you endorsed mechanism
This is very easy. Just create a folder named 'endorsed' and put this 2.1 versioned jar(the jar file which you want to get loaded) inside this endorsed folder and place this endorsed folder inside lib of jre which will be inside jdk.

As far as possible use latest version of jdk1.6(means jdk 1.6.18 not jdk1.6.0)