Knowledge Base
Published Sep. 10, 2025

Troubleshooting java.lang.NoClassDefFoundError and java.lang.ClassNotFoundException Optional Dependency Errors

Written By

Mariano Alvaro

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Issue

  • When starting up Liferay, the following errors are observed: java.lang.NoClassDefFoundError or java.lang.ClassNotFoundException.

Environment

  • Liferay DXP with deployed custom modules including optional dependencies.

Resolution

  1. Review the deployed MANIFEST.MF inside the module or the bnd.bnd in the source code and check if the dependency to the package that contains the class is defined as optional.
  2. Analyze the convenience of removing the optional modifier.

Optional dependencies should be avoided as much as possible. They bypass OSGi validations that ensure a module can be safely started without having classes missing during runtime.

Additional Information

  • The simplest module designs rely on normal dependencies. If an optional dependency seems desirable, it's often the case that your module is trying to provide distinct types of functionality. In such a situation, it's best to split your module into multiple modules that each provide smaller, more focused functionality.
  • If you install the module when the optional dependency is missing from Liferay DXP's OSGi runtime, your controller component catches a ClassNotFoundException and logs a warning or info message (or takes whatever other action you implement to handle this case). If you install the optional dependency, refreshing your module triggers the OSGi bundle lifecycle events that trigger your controller's activate method and your check for the optional dependency. Since your dependency exists, your client component uses it.
Did this article resolve your issue ?

Knowledge Base