JVM class loader
JVM contain loaders:
- BootStrapClassLoader
jvm need foundation class - ExtClassLoader
load$JAVA_HOME$/jre/lib/ext
jars - AppClassLoader
$CLASS_PATH$ and -classpath, and class not be contained above - CustomClassLoader
self define class loader[progress]
different classloader’s class can’t use in mix,
even if the class is same package name and same class name.
JVM use delegation model
- pass request to father until the top
- if top can’t load return to sub level
- if the floor can’t load class throw ClassNotFoundException
So if a same path class be put in $CLASS_PATH$ directory, java will load
$CLASS_PATH$ class first.
Tomcat class loader
Tomcat loader like this:
- Bootstrap
guilde class loader$JAVA_HOME$/jre/lib/ext
jars - System
tomcat container loading$CATALINA_HOME$/bin
jars - Common
app common use class$CATALINA_HOME$/lib
jars - WebApp
WEB-INF/classes
andWEB-INF/lib
developer’s workspace
Problem
When developing throw an exception from java.io.ObjectStreamClass
row:20341
2
3
4
5
6
7throw new ClassCastException(
"cannot assign instance of " +
val.getClass().getName() + " to field " +
f.getDeclaringClass().getName() + "." +
f.getName() + " of type " +
f.getType().getName() + " in instance of " +
obj.getClass().getName());
From inspect the class type is a blank type only a path name.
Manually change the Class type suppress exception then jump breakpoint
the throw a exception like this:
Key Point
The Class used to communication is for other application use,
but the class contain a property that is from acceptor’s offical workspace.
Two application use a same tomcat and
put the dependent jar in $CATALINA_HOME$/lib
.
It lead to a problem, the acceptor’s application load object and it’s field
class in two different classloader. one is WebAppClassLoader
, on is bootstrap
- In object receive acceptor object use the common class jar[find in floor level]
- When object comes the property field’s class be found in workspace
but object’s classloader can’t see,
so as it’s sign target field class is just a shell. - When suppress exception and jump breakpoint,
the business class violate the loader constraint.