Voici la disposition du répertoire que j'ai dans mon projet maven:
.
├── pom.xml
└── src
└── main
├── Java
│ └── biz
│ └── tugay
│ └── web
│ └── servlet
│ └── MainServlet.Java
├── resources
│ └── log4j.properties
└── webapp
└── WEB-INF
└── web.xml
parties relavent pom.xml comme suit:
</dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.Apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.Apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>bare-webapp</finalName>
<plugins>
<plugin>
<groupId>org.Eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.1.v20140609</version>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<log4j.version>2.8.2</log4j.version>
</properties>
Et voici mon web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
</web-app>
et voici enfin à quoi ressemble log4j.properties:
# suppress inspection "UnusedProperty" for whole file
# logger level configurations
log4j.rootLogger=ALL, console
# configuration for console outputs
log4j.appender.console=org.Apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.Apache.log4j.PatternLayout
log4j.appender.console.layout.conversionPattern=[%t] %-5p %c - %m%n
Donc actuellement tout va bien (je démarre jetty avec: mvn jetty: start) et quand je visite "/" je vois dans la console:
20:38:09.433 [qtp1503674351-26] ERROR biz.tugay.web.servlet.MainServlet - Serving request!
Tout va bien ..
<log4j.version>2.9.1</log4j.version>
après jetée: début j'obtiens:
[WARNING] Failed startup of context o.e.j.m.p.JettyWebAppContext@fb0d6fe{/,file:/Users/koraytugay/bare-webapp/src/main/webapp/,STARTING}{file:/Users/koraytugay/bare-webapp/src/main/webapp/}
MultiException[Java.lang.RuntimeException: Error scanning entry META-INF/versions/9/org/Apache/logging/log4j/util/ProcessIdUtil.class from jar file:/Users/koraytugay/.m2/repository/org/Apache/logging/log4j/log4j-api/2.9.1/log4j-api-2.9.1.jar, Java.lang.RuntimeException: Error scanning entry META-INF/versions/9/org/Apache/logging/log4j/util/StackLocator.class from jar file:/Users/koraytugay/.m2/repository/org/Apache/logging/log4j/log4j-api/2.9.1/log4j-api-2.9.1.jar]
at org.Eclipse.jetty.annotations.AnnotationConfiguration.scanForAnnotations(AnnotationConfiguration.Java:530)
at org.Eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.Java:441)
at org.Eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.Java:471)
at org.Eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.Java:1329)
at org.Eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.Java:744)
at org.Eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.Java:497)
at org.Eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.Java:281)
at org.Eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.Java:68)
at org.Eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.Java:132)
at org.Eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.Java:114)
at org.Eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.Java:60)
at org.Eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.Java:154)
at org.Eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.Java:68)
at org.Eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.Java:132)
at org.Eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.Java:114)
at org.Eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.Java:60)
at org.Eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.Java:68)
at org.Eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.Java:132)
at org.Eclipse.jetty.server.Server.start(Server.Java:357)
at org.Eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.Java:114)
at org.Eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.Java:60)
at org.Eclipse.jetty.server.Server.doStart(Server.Java:324)
at org.Eclipse.jetty.maven.plugin.JettyServer.doStart(JettyServer.Java:68)
at org.Eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.Java:68)
at org.Eclipse.jetty.maven.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.Java:564)
at org.Eclipse.jetty.maven.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.Java:360)
at org.Eclipse.jetty.maven.plugin.JettyRunMojo.execute(JettyRunMojo.Java:168)
at org.Apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.Java:134)
at org.Apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.Java:207)
at org.Apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.Java:153)
at org.Apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.Java:145)
at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.Java:116)
at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.Java:80)
at org.Apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.Java:51)
at org.Apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.Java:128)
at org.Apache.maven.DefaultMaven.doExecute(DefaultMaven.Java:307)
at org.Apache.maven.DefaultMaven.doExecute(DefaultMaven.Java:193)
at org.Apache.maven.DefaultMaven.execute(DefaultMaven.Java:106)
at org.Apache.maven.cli.MavenCli.execute(MavenCli.Java:863)
at org.Apache.maven.cli.MavenCli.doMain(MavenCli.Java:288)
at org.Apache.maven.cli.MavenCli.main(MavenCli.Java:199)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.Java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.Java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.Java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.Java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.Java:47)
Java.lang.RuntimeException: Error scanning entry META-INF/versions/9/org/Apache/logging/log4j/util/ProcessIdUtil.class from jar file:/Users/koraytugay/.m2/repository/org/Apache/logging/log4j/log4j-api/2.9.1/log4j-api-2.9.1.jar
at org.Eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.Java:913)
at org.Eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.Java:831)
at org.Eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.Java:159)
at org.Eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.Java:542)
at org.Eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.Java:607)
at org.Eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.Java:536)
at Java.lang.Thread.run(Thread.Java:745)
Caused by: Java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.Eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.Java:973)
at org.Eclipse.jetty.annotations.AnnotationParser.parseJarEntry(AnnotationParser.Java:956)
at org.Eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.Java:909)
... 6 more
Java.lang.RuntimeException: Error scanning entry META-INF/versions/9/org/Apache/logging/log4j/util/StackLocator.class from jar file:/Users/koraytugay/.m2/repository/org/Apache/logging/log4j/log4j-api/2.9.1/log4j-api-2.9.1.jar
at org.Eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.Java:913)
at org.Eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.Java:831)
at org.Eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.Java:159)
at org.Eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.Java:542)
at org.Eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.Java:607)
at org.Eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.Java:536)
at Java.lang.Thread.run(Thread.Java:745)
Caused by: Java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.Eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.Java:973)
at org.Eclipse.jetty.annotations.AnnotationParser.parseJarEntry(AnnotationParser.Java:956)
at org.Eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.Java:909)
... 6 more
[WARNING] !RequestLog
[INFO] Started ServerConnector@42c81ca{HTTP/1.1}{0.0.0.0:8080}
[INFO] Started @2609ms
[INFO] Started Jetty Server
Comment faire fonctionner jetty avec log4j 2.9.1? Y a-t-il un problème dans ma configuration ou est-ce un bug dans jetty ou log4j?
log4j 2.9 et versions ultérieures sont pots multi-versions pour Java 9.
Votre version Jetty ne prend pas en charge cela. Mettez Jetty à niveau vers une version compatible avec Java 9 ou utilisez log4j 2.8.x.
Voir le numéro 1797 de Jetty: JEP 238 - Les fichiers JAR à plusieurs versions interrompent l'analyse bytecode .
L'erreur suivante s'est produite: com.ibm.ws.metadata.annotations.AnnotationException: le traitement des annotations a échoué pour la classe: META-INF/versions/9/module-info.class
L'erreur ci-dessus sera rencontrée dans WAS 9, lorsque nous essayons de déployer et d'annuler le déploiement de plusieurs applications trop souvent. Le serveur devient défectueux.
Lorsque je l'ai rencontré, j'ai désinstallé toutes les applications du serveur. Et redémarré 2-3 fois. Une fois le serveur redémarré, j'ai essayé de le déployer à nouveau et l'application a fonctionné comme prévu.