I'm currently trying to build an app with log4j/slf4j and java 11 but I'm facing this problem at runtime:
2018-12-10 22:09:27,225 main INFO Cannot initialize scripting support because this JRE does not support it. java.lang.NoClassDefFoundError: javax/script/ScriptEngineManager
at [email protected]/org.apache.logging.log4j.core.script.ScriptManager.<init>(ScriptManager.java:69)
at [email protected]/org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:216)
at [email protected]/org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at [email protected]/org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at [email protected]/org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at [email protected]/org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at [email protected]/org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at [email protected]/org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at [email protected]/org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j/org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j/org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:121)
at [email protected]/org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:49)
at org.apache.logging.log4j/org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
at [email protected]/org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j/org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:355)
at org.slf4j/org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:380)
at fr.mrcraftcod.nameascreated/fr.mrcraftcod.nameascreated.NameAsCreated.<clinit>(NameAsCreated.java:39)
Caused by: java.lang.ClassNotFoundException: javax.script.ScriptEngineManager
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 17 more
The code that is at the origin of this is the initialization of my logger:
private static final Logger LOGGER = LoggerFactory.getLogger(NameAsCreated.class);
I have dependencies on:
I'm on OSX Mojave with Java version:
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment AdoptOpenJDK (build 11+28-201810021910)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11+28-201810021910, mixed mode)
Does someone have an idea of what I'm doing wrong and how I can solve this?
Everything works, except the specific file logger. Logging works fine on previous Java versions - 10, 9, 8, but not on Java 11.
If you used Log4j2 with SLF4J, the only thing you need is replacing Log4j2 JAR files (or maven dependencies) by JDK logger Binding. You do not want to touch any source files in order to replace your logger.
The Log4j 2 Setup The latest version can be found here: log4j-api, log4j-core, log4j-slf4j-impl. The actual logging configuration adheres to native Log4j 2 configuration. Note that the Logger and LoggerFactory belong to the org. slf4j package.
If you are using log4j-over-slf4j. jar in conjunction with the SLF4J API, you are safe unless the underlying implementation is log4j 2.
According to the Log4j documentation:
Log4j provides support for JSR 223 scripting languages to be used in some of its components.
and as said in the comments by Alan Bateman
from Java 9 you have to add explicitly the java scripting module either with --add-modules java.scripting
or in module-info.java
.
Note also that the module jdk.scripting.nashorn
is deprecated in Java 11 and will be removed in a future release.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With