Auparavant, le projet était sur Tomcat 8 et JDK 8, cela fonctionnait bien, mais lorsque j'ai migré mon projet sur Tomcat 9 et JDK 10, cela me donne une erreur comme suit:
Oct 05, 2018 11:02:01 AM org.Apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
Java.lang.IllegalArgumentException
at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.Java:170)
at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.Java:153)
at jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.Java:424)
at org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener.process(AnnotationAcceptingListener.Java:170)
at org.glassfish.jersey.server.ResourceConfig.scanClasses(ResourceConfig.Java:915)
at org.glassfish.jersey.server.ResourceConfig._getClasses(ResourceConfig.Java:869)
at org.glassfish.jersey.server.ResourceConfig.getClasses(ResourceConfig.Java:775)
at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.Java:1206)
at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.Java:1178)
at org.glassfish.jersey.server.ResourceConfig.createRuntimeConfig(ResourceConfig.Java:1174)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.Java:345)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.Java:392)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.Java:177)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.Java:369)
at javax.servlet.GenericServlet.init(GenericServlet.Java:158)
at org.Apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.Java:1124)
at org.Apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.Java:1079)
at org.Apache.catalina.core.StandardWrapper.load(StandardWrapper.Java:971)
at org.Apache.catalina.core.StandardContext.loadOnStartup(StandardContext.Java:4829)
at org.Apache.catalina.core.StandardContext.startInternal(StandardContext.Java:5143)
at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:183)
at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1429)
at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1419)
at Java.base/Java.util.concurrent.FutureTask.run(Unknown Source)
at org.Apache.Tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.Java:75)
at Java.base/Java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:944)
at org.Apache.catalina.core.StandardHost.startInternal(StandardHost.Java:839)
at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:183)
at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1429)
at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1419)
at Java.base/Java.util.concurrent.FutureTask.run(Unknown Source)
at org.Apache.Tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.Java:75)
at Java.base/Java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:944)
at org.Apache.catalina.core.StandardEngine.startInternal(StandardEngine.Java:261)
at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:183)
at org.Apache.catalina.core.StandardService.startInternal(StandardService.Java:422)
at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:183)
at org.Apache.catalina.core.StandardServer.startInternal(StandardServer.Java:770)
at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:183)
at org.Apache.catalina.startup.Catalina.start(Catalina.Java:682)
at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at Java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at Java.base/Java.lang.reflect.Method.invoke(Unknown Source)
at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:350)
at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:492)
Mon fichier pom.xml est:
<project xmlns="http://maven.Apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.Apache.org/POM/4.0.0 http://maven.Apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.BAE</groupId>
<artifactId>BAE</artifactId>
<version>1.0.1-SNAPSHOT</version>
<name>BAE Maven Webapp</name>
<url>http://maven.Apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.
/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
</dependency>
<!-- Servlet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.inject/javax.inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.json/javax.json-api -->
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.interceptor/jboss-interceptor-api -->
<dependency>
<groupId>org.jboss.interceptor</groupId>
<artifactId>jboss-interceptor-api</artifactId>
<version>1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/xerces/xercesImpl -->
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml/jackson-xml-databind -->
<!-- https://mvnrepository.com/artifact/io.swagger/swagger-models -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.swagger/swagger-annotations -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.swagger/swagger-jaxrs -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.swagger/swagger-core -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<version>1.5.20</version>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet-core -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.Microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.Microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sourceforge.jtds/jtds -->
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json</artifactId>
<version>2.0-m05</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider -->
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.9.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.jaxrs/jackson-jaxrs-base -->
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-base</artifactId>
<version>2.9.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.9.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-joda -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.9.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.Eclipse/yasson -->
<dependency>
<groupId>org.Eclipse</groupId>
<artifactId>yasson</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>BAE_4_4</finalName>
<sourceDirectory>src\main\Java</sourceDirectory>
<testSourceDirectory>src/test</testSourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.Java</exclude>
<exclude>main/**</exclude>
<exclude>test/**</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.Apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.Apache.maven.plugins</groupId>
<artifactId>maven-Eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<!-- Always download and attach dependencies source code -->
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<!-- Avoid type mvn Eclipse:eclipse -Dwtpversion=2.0 -->
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
<!-- For Maven Tomcat Plugin -->
<plugin>
<groupId>org.Apache.Tomcat.maven</groupId>
<artifactId>Tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/BAE</path>
</configuration>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
</project>
Ci-dessus, tous les fichiers jar des dépendances que j'ai utilisés dans Tomcat 8 et jdk 8.
Quelqu'un peut-il me suggérer quelle est la cause et la solution de ce problème?
Merci d'avance....
Pour utiliser Java 10, passez à Jersey 2.27 (qui est le dernier en date de cette date (10/5/18)).
Java.lang.IllegalArgumentException
at jersey.repackaged.org.objectweb.asm.ClassReader.<init>
Jersey reconditionne asm et place ces fichiers de classe dans le jersey-server
pot. Juste en fouillant dans le pot de mon IDE, j'ai regardé le constructeur ClassReader
(c'est ce que <init>
signifie) pour voir où IllegalArgumentException est levée. Remarque, je regarde actuellement la version 2.25.1 de Jersey
public ClassReader(byte[] b, int off, int len) {
this.b = b;
if (this.readShort(off + 6) > 53) {
throw new IllegalArgumentException();
}
Le 53 est le version du fichier de classe . Selon ce lien, 53 est pour Java 9. Il semble donc que Jersey 2.25.1 ne supporte que jusqu'à Java 9. J'ai donc changé la version de dépendance de Jersey à 2.26, et j'ai regardé le constructeur ClassReader
et c'était exactement la même chose. Donc je suis passé à Jersey 2.27, et c'est ce que j'ai vu
public ClassReader(final byte[] b, final int off, final int len) {
this.b = b;
// checks the class version
// added "support" for Java 11 compiled classes
if (readShort(off + 6) > Opcodes.V11) {
throw new IllegalArgumentException();
}
Remarquez le Opcodes.V11
(ce qui, je suppose, est Java 11). Il ressemble donc à Java 10+ support, vous devez passer à Jersey 2.27, comme mentionné également dans ce problème connexe
Après avoir vu votre pom, vous devez vous assurer que vous modifiez la version Jersey sur toutes vos dépendances Jersey. Et vous avez aussi tellement de dépendances inutiles. Voici tout ce dont vous avez besoin. Supprimez tout autre élément dont le nom contient Jersey.
CONSERVEZ CES
Passer à 2.27
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.27</version>
</dependency>
ENLEVEZ CES
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.25</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.25</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json</artifactId>
<version>2.0-m05</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
AJOUTER L'EXCLUSION
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.13</version>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Voir le Jersey Guide de migration pour d'autres problèmes que vous pourriez rencontrer lors de la migration vers la version 2.27
La seule chose dont vous aurez besoin si vous migrez depuis la version antérieure à 2.26 est le jersey-hk2
dépendance. Voir cet article pour savoir pourquoi.
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.27</version>
</dependency>