When deploying applications on WildFly, encountering a
log4j2 core libs and log4j2 API mismatch issue is not uncommon. This issue, presented as java.lang.NoSuchFieldError: EMPTY_BYTE_ARRAY, arises due to discrepancies between the Log4j2 core libraries used within the application and the Log4j2 API provided by WildFly’s modules.
Firstly, the mismatch occurs when the application uses a specific version of Log4j2 core libraries that conflicts with the Log4j2 API provided by WildFly. This conflict leads to inconsistencies and
NoSuchFieldError or other runtime errors related to Log4j2 components:
To resolve the Log4j2 core and API mismatch in WildFly, follow these steps:
- Identify Versions: Firstly, check and verify the Log4j2 core library version used within the application and the Log4j2 API provided by WildFly.
- Exclude Module: Then, create or update the
jboss-deployment-structure.xmlfile within the
src/main/webapp/WEB-INF/directory of the application. Exclude the
org.apache.logging.log4j.apimodule to prevent the server from using its Log4j2 API module. Example snippet:
<jboss-deployment-structure> <deployment> <exclusions> <module name="org.apache.logging.log4j.api"/> </exclusions> </deployment> </jboss-deployment-structure>
Test and Validate: After making these adjustments, thoroughly test the application to ensure that the Log4j2 core and API are in sync and functioning without any runtime errors.
To learn how configure Log4j 2 properly on WildFly we recommend checking this article: How to use Log4j2 in your WildFly applications
Resolving the Log4j2 core and API mismatch in WildFly involves aligning the Log4j2 core libraries within the application with the Log4j2 API provided by the server. By excluding conflicting modules and ensuring version compatibility, the application can function seamlessly within the WildFly environment without runtime issues related to Log4j2.
This approach helps maintain consistency and stability in logging functionalities, ensuring a smoother deployment experience on WildFly.Found the article helpful? if so please follow us on Socials