问题
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 org.apache.logging.log4j.core@2.11.1/org.apache.logging.log4j.core.script.ScriptManager.<init>(ScriptManager.java:69)
at org.apache.logging.log4j.core@2.11.1/org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:216)
at org.apache.logging.log4j.core@2.11.1/org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core@2.11.1/org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core@2.11.1/org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core@2.11.1/org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core@2.11.1/org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core@2.11.1/org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core@2.11.1/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 org.apache.logging.log4j.slf4j@2.11.1/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 org.apache.logging.log4j.slf4j@2.11.1/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:
- org.apache.logging.log4j:log4j-api:2.11.1
- org.apache.logging.log4j:log4j-core:2.11.1
- org.apache.logging.log4j:log4j-slf4j18-impl:2.11.1
- A maven project that depends on org.slf4j:slf4j-api:1.8.0-beta2
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?
回答1:
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.
来源:https://stackoverflow.com/questions/53714010/log4j2-slf4j-and-java-11