Resolving ClassNotFound Exceptions in JSPs and TLDs
Madeleine Clay
更新
Issue
A ClassNotFound exception occurs when referencing classes from JSPs or TLDs, even when using a wildcard (*) in the import-package header of liferay-plugin-package.properties.
Example error message:
Unable to dispatch request: The class com.example.package.Class specified in the method signature in TLD for the function exampleFunction cannot be found.
Environment
Liferay DXP 7.4+
Resolution
The wildcard (*) in the import-package header of liferay-plugin-package.properties only imports packages referenced from compiled artifacts. JSPs and TLDs are not compiled during the module build process; they are compiled at runtime by the server. Therefore, the build tool cannot identify their dependencies.
To resolve the ClassNotFound exception, explicitly declare the required packages in the import-package header along with the wildcard:
Import-Package: com.example.required.package, *
This ensures that OSGi can resolve the required class at runtime.