Java Reference
In-Depth Information
ClassNotFoundException occurs when you're attempting to dynamically
load a resource that can't be found. The reason for this exception can be a
missing library at the correct loader level—you know, the JAR file containing
the class that can't be found. If you're loading a resource or property file in
your application, make sure you use
Thread.currentThread().getContextClassLoader() .getRe-
sourceAsStream() .
NoClassDefFoundException is thrown when code tries to instantiate an ob-
ject or when dependencies of a previously loaded class can't be resolved. Typically
you run into this issue when all dependent libraries aren't at the same class-loader
level.
ClassCastException normally is the result of duplication of classes at dif-
ferent levels. This occurs in the same-class, different-loader situation; that is, you
try to cast a class loaded by class loader L1 with another class instance loaded by
class loader L2.
NamingException is typically thrown when a JNDI lookup fails, because the
container tries to inject a resource for an EJB that doesn't exist. The stack trace for
this exception gives the details about which lookup is failing. Make sure that your
dependencies on data sources, EJBs, and other resources resolve properly.
NotSerializableException is thrown when an object needs to be moved
from in-memory to some kind of byte[] form but the object doesn't support this
conversion. This can happen if stateful session beans need to be passivated and
saved to disk to free up memory, or it can happen if session beans are accessed
remotely and the objects they return need to be transferred over the network.
Whatever the reason, if the object isn't serializable, you'll get this exception. The
best way to avoid this is to add a JUnit test to assert the object is serializable. Typ-
ically objects start life with the ability to be serialized, but as time goes on and the
objects are updated, nonserializable stuff creeps in.
• Your deployment may fail due to an invalid XML deployment descriptor. Make
sure that your descriptors comply with the schema. You can do this by using an
IDE to build your applications instead of manually editing XML descriptor files.
13.7. Summary
At the heart of Java EE applications lies the art of assembling and packaging Enterprise
applications. This chapter briefly introduced the concepts of class loading and how the de-
pendencies between classes in an EE application are specified by the Java Enterprise spe-
Search WWH ::




Custom Search