Friday, June 27, 2008

JBoss and Tomcat problems with Java ClassLoader

Last week I was stucked with some specified java problem.
i made a dynamic web application (servlets and JSP stuff) and used some external libraries (JARs) inside WAR-file. there was under «WebContent/WEB-INF/lib/».

The problem description is that some classes is not visible from where it is being loaded. This happens when you have an isolated deployment (like a WAR) and you try to load it from outside the WAR. This may not be directly. e.g. A WAR class loads a class from outside the WAR which in turn tries to load a class from inside the war.

To understand the root of the problem, it is recommended to look at the Advanced JBoss Class Loading.

And solution was to place these JAR-files not in WAR, but in «jboss/server/default/lib/ext» folder. Or even better — make there you folder and add following in the «jboss/server/default/conf/jboss-service.xml».

<classpath codebase="${jboss.server.lib.url:lib}/YOUR_DIR" archives="*"/>

See also:
Why do I get ClassNotFoundException or NoClassDefFoundError
Classloader/Classpath problem

All this true for JBoss 4.2.0.

No comments:

Post a Comment