4.2. Debug Migration Issues
4.2.1. Debug and Resolve Migration Issues Copy linkLink copied to clipboard!
4.2.2. Debug and Resolve ClassNotFoundExceptions and NoClassDefFoundErrors Copy linkLink copied to clipboard!
ClassNotFoundExceptions usually occur due to an unresolved dependency. This means you must explicitly define the dependencies on other modules or copy JARs from external sources.
- First, try to find the missing dependency. This is described in more detail here: Section 4.2.3, “Find the JBoss Module Dependency”
- If there is not a module for the missing class, find the JAR in the previous install. For more information, see Section 4.2.4, “Find the JAR in the Previous Install”
4.2.3. Find the JBoss Module Dependency Copy linkLink copied to clipboard!
ClassNotFoundException by looking in the EAP_HOME/modules/system/layers/base/ directory. If you find a module for the class, you must add a dependency to the manifest entry.
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.Log
from [Module "deployment.TopicIndex.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:188)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.Log
from [Module "deployment.TopicIndex.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:188)
Procedure 4.5. Find the Dependency
- First determine if there is an obvious module for the class.
- Navigate to the
EAP_HOME/modules/system/layers/base/directory and look for the module path matching class named in theClassNotFoundException.You find the module pathorg/apache/commons/logging/. - Open the
EAP_HOME/modules/system/layers/base/org/apache/commons/logging/main/module.xmlfile and find the module name. In this case, it is "org.apache.commons.logging". - Add the module name to the Dependencies in the
MANIFEST.MFfile:Manifest-Version: 1.0 Dependencies: org.apache.commons.logging
Manifest-Version: 1.0 Dependencies: org.apache.commons.loggingCopy to Clipboard Copied! Toggle word wrap Toggle overflow
- If there is no obvious module path for the class, you may need to find the dependency in another location.
- Find the class named by the
ClassNotFoundExceptionin the Tattletale report. - Find the module containing the JAR in the
EAP_HOME/modulesdirectory and find the module name as in the previous step.
4.2.4. Find the JAR in the Previous Install Copy linkLink copied to clipboard!
lib/ directory.
ClassNotFoundException trace in the log:
Caused by: java.lang.NoClassDefFoundError: org/hibernate/validator/ClassValidator at java.lang.Class.getDeclaredMethods0(Native Method)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/validator/ClassValidator at java.lang.Class.getDeclaredMethods0(Native Method)
- Open a terminal and navigate to the
EAP5_HOME/directory. - Issue the command:
grep 'org.hibernate.validator.ClassValidator' `find . \-name '*.jar'` - You might see more than one result. In this case, the following result is the JAR we need:
Binary file ./jboss-eap-5.1/seam/lib/hibernate-validator.jar matches
Binary file ./jboss-eap-5.1/seam/lib/hibernate-validator.jar matchesCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Copy this JAR to the application's
lib/directory.If you find that you need a large number of JARs, it may be easier to define a module for the classes. For more information, see Modules in the chapter entitled Get Started Developing Applications in the Development Guide for JBoss EAP 6 on https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/?version=6.4. - Rebuild and redeploy the application.
4.2.5. Debug and Resolve ClassCastExceptions Copy linkLink copied to clipboard!
- Search the application to find all JAR(s) that contain the class named by the
ClassCastException. If there is a module defined for the class, find and remove the duplicate JAR(s) from the application's WAR or EAR. - Find the JBoss module containing the class and explicitly define the dependency in the
MANIFEST.MFfile or in thejboss-deployment-structure.xmlfile. For more information, see Class Loading and Subdeployments in the chapter entitled Class Loading and Modules in the Development Guide for JBoss EAP 6 on https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/?version=6.4. - If you are not able to resolve it using the steps above, you can often determine the cause of the problem by printing the class loader information to the log. For example, you see the following
ClassCastExceptionin the log:java.lang.ClassCastException: com.example1.CustomClass1 cannot be cast to com.example2.CustomClass2
java.lang.ClassCastException: com.example1.CustomClass1 cannot be cast to com.example2.CustomClass2Copy to Clipboard Copied! Toggle word wrap Toggle overflow - In your code, print the class loader information for the classes named by the
ClassCastExceptionto the log, for example:logger.info("Class loader for CustomClass1: " + com.example1.CustomClass1.getClass().getClassLoader().toString()); logger.info("Class loader for CustomClass2: " + com.example2.CustomClass2.getClass().getClassLoader().toString());logger.info("Class loader for CustomClass1: " + com.example1.CustomClass1.getClass().getClassLoader().toString()); logger.info("Class loader for CustomClass2: " + com.example2.CustomClass2.getClass().getClassLoader().toString());Copy to Clipboard Copied! Toggle word wrap Toggle overflow - The information in the log shows which modules are loading the classes and, based on your application, you need to remove or move the conflicting JAR(s).
4.2.6. Debug and Resolve DuplicateServiceExceptions Copy linkLink copied to clipboard!
- Rename the JAR file to a name that is different than the WAR so the generated web and WAR contexts is unique.
- Provide a
<context-root>element in thejboss-web.xmlfile. - Provide a
<context-root>element in thejboss-webservices.xmlfile. - Customize the
<context-root>element for the WAR in theapplication.xmlfile.
4.2.7. Debug and Resolve JBoss Seam Debug Page Errors Copy linkLink copied to clipboard!
Figure 4.1. JBoss Seam Debug Page
- Expand the
Componentsection on the page and look for theorg.jboss.seam.caughtExceptioncomponent. - The cause and stack trace should point you to the missing dependencies.
Figure 4.2. Component
org.jboss.seam.caughtExceptioninformation - Use the technique described in Section 4.2.2, “Debug and Resolve ClassNotFoundExceptions and NoClassDefFoundErrors” to resolve module dependencies.In the example above, the simplest solution is to add
org.slf4jto theMANIFEST.MFManifest-Version: 1.0 Dependencies: org.slf4j
Manifest-Version: 1.0 Dependencies: org.slf4jCopy to Clipboard Copied! Toggle word wrap Toggle overflow Another option is to add a dependency for the module to thejboss-deployment-structure.xmlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow