java.lang.NoClassDefFoundError: org.apache.log4j.Logger - RECOMPILING extensions EWM7.0.2
Hi,
I have migrated EWM from v6.0.6.1 to v7.0.2
Trying to migrate the ccm/sites i have the following error in ccm.log related to a lot of custom plugins: java.lang.NoClassDefFoundError: org.apache.log4j.Logger
I have downloaded the SDK 7.0.2 and i cant import the class import org.apache.log4j.Logger;
The server is using liberty.
How can i log my extensions now?
Can i import the class?
Thank you
Accepted answer
Hi Alvaro,
it is absolutely a best practice, to try and package EWM extensions with the EWM SDK that matches the version of the EWM server the plugins are supposed to work in.
Having said that, I have seen pretty much no cases where the API broke in a way that you would not be able to deploy in higher versions of EWM. I believe some changes of the Java Version require a rebuild.
Again having said that there is an exception, which is 7.0.2SR1. The removal of Log4J1 and the change to Log4J2 absolutely breaks extensions that use Log4J (1).
You must setup a new development environment with the new SDK for 7.0.2SR1 and you will have to modify your code. You definitely need the code for the plugin in order to do that.
The code changes are for example the removal of the old imports for log4j and adding new imports:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Getting the logger now looks like this:
private static final Logger logger = LogManager.getLogger();
Changing the warning level now looks like this.
Configurator.setLevel(LogManager.getLogger(logger).getName(),Level.WARN);
Also see my experience with the SDK and the plain Java Client Libraries for 7.0.2SR1 and beyond here: https://rsjazz.wordpress.com/2022/09/13/workitem-command-line-and-rtc-ewm-extensions-workshop-for-7-0-2-sr1/
One other answer
log4j v1 was removed from ELM applications in order to address security vulnerabilities. Custom code should instead be referencing log4j v2 - see https://logging.apache.org/log4j/2.x/ for details.