web-dev-qa-db-fra.com

Obtenir une multitude d'avertissements "analysés à partir de plusieurs emplacements" dans une application Web Jersey simple

Je reviens à Java après un certain temps et j'essaie d'obtenir une simple API RESTful avec Java 8, Jersey 2.27 et Jetty 9.4.9 à l'aide de la ligne de commande. L'application fonctionne , mais je continue à recevoir des centaines d'avertissements tels que:

2018-04-27 01:17:24.845:WARN:oeja.AnnotationParser:main: Unrecognized runtime asm version, assuming 393216
2018-04-27 01:17:24.945:WARN:oeja.AnnotationParser:qtp988458918-12: javax.el.ArrayELResolver scanned from multiple locations: jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/el-api-2.2.jar!/javax/el/ArrayELResolver.class, jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/el/ArrayELResolver.class
2018-04-27 01:17:24.949:WARN:oeja.AnnotationParser:qtp988458918-12: javax.el.BeanELResolver$BeanProperties scanned from multiple locations: jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/el-api-2.2.jar!/javax/el/BeanELResolver$BeanProperties.class, jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/el/BeanELResolver$BeanProperties.class
2018-04-27 01:17:24.952:WARN:oeja.AnnotationParser:qtp988458918-12: javax.el.BeanELResolver$BeanProperty scanned from multiple locations: jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/el-api-2.2.jar!/javax/el/BeanELResolver$BeanProperty.class, jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/el/BeanELResolver$BeanProperty.class
2018-04-27 01:17:24.954:WARN:oeja.AnnotationParser:qtp988458918-12: javax.el.BeanELResolver scanned from multiple locations: jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/el-api-2.2.jar!/javax/el/BeanELResolver.class, jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/el/BeanELResolver.class
2018-04-27 01:17:24.959:WARN:oeja.AnnotationParser:qtp988458918-12: javax.el.CompositeELResolver scanned from multiple locations: jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/el-api-2.2.jar!/javax/el/CompositeELResolver.class, jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/el/CompositeELResolver.class
2018-04-27 01:17:24.961:WARN:oeja.AnnotationParser:qtp988458918-12: javax.el.ELContext scanned from multiple locations: jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/el-api-2.2.jar!/javax/el/ELContext.class, jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/el/ELContext.class
2018-04-27 01:17:24.962:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.Generated scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/Generated.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/Generated.class
2018-04-27 01:17:24.962:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.ManagedBean scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/ManagedBean.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/ManagedBean.class
2018-04-27 01:17:24.962:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.PostConstruct scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/PostConstruct.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/PostConstruct.class
2018-04-27 01:17:24.963:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.PreDestroy scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/PreDestroy.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/PreDestroy.class
2018-04-27 01:17:24.963:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.Priority scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/Priority.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/Priority.class
2018-04-27 01:17:24.963:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.Resource$AuthenticationType scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/Resource$AuthenticationType.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/Resource$AuthenticationType.class
2018-04-27 01:17:24.963:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.Resource scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/Resource.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/Resource.class
2018-04-27 01:17:24.963:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.Resources scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/Resources.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/Resources.class
2018-04-27 01:17:24.963:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.security.DeclareRoles scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/security/DeclareRoles.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/security/DeclareRoles.class
2018-04-27 01:17:24.964:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.security.DenyAll scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/security/DenyAll.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/security/DenyAll.class
2018-04-27 01:17:24.964:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.security.PermitAll scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/security/PermitAll.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/security/PermitAll.class
2018-04-27 01:17:24.964:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.security.RolesAllowed scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/security/RolesAllowed.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/security/RolesAllowed.class
2018-04-27 01:17:24.964:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.security.RunAs scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/security/RunAs.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/security/RunAs.class
2018-04-27 01:17:24.964:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.sql.DataSourceDefinition scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/sql/DataSourceDefinition.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/sql/DataSourceDefinition.class
2018-04-27 01:17:24.965:WARN:oeja.AnnotationParser:qtp988458918-15: javax.annotation.sql.DataSourceDefinitions scanned from multiple locations: jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/annotation/sql/DataSourceDefinitions.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.annotation-api-1.2.jar!/javax/annotation/sql/DataSourceDefinitions.class
2018-04-27 01:17:24.962:WARN:oeja.AnnotationParser:qtp988458918-12: javax.el.ELContextEvent scanned from multiple locations: jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/el-api-2.2.jar!/javax/el/ELContextEvent.class, jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/el/ELContextEvent.class
2018-04-27 01:17:24.966:WARN:oeja.AnnotationParser:qtp988458918-12: javax.el.ELContextListener scanned from multiple locations: jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/el-api-2.2.jar!/javax/el/ELContextListener.class, jar:file:///paste4j/deployment/jetty-runner-9.4.9.v20180320.jar!/javax/el/ELContextListener.class
2018-04-27 01:17:24.966:WARN:oeja.AnnotationParser:qtp988458918-17: javax.inject.Inject scanned from multiple locations: jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.inject-1.jar!/javax/inject/Inject.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.inject-2.5.0-b42.jar!/javax/inject/Inject.class
2018-04-27 01:17:24.966:WARN:oeja.AnnotationParser:qtp988458918-17: javax.inject.Named scanned from multiple locations: jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.inject-1.jar!/javax/inject/Named.class, jar:file:///tmp/jetty-0.0.0.0-8081-paste4j.war-_-any-8355640322316327743.dir/webapp/WEB-INF/lib/javax.inject-2.5.0-b42.jar!/javax/inject/Named.class

J'ai extrait le contenu de jaxrs-ri-2.27.Zip de https://jersey.github.io/download.html dans le répertoire du projet WEB-INF\lib\, de sorte que tous les fichiers JAR du fichier Zip se trouvent dans le même répertoire.

Puis je le compile avec:

# In project root
javac -classpath "WEB-INF/lib/*" WEB-INF/classes/com/paste/ws/*.Java
jar -cvf paste4j.war WEB-INF/*

Et enfin, essayez de le lancer avec:

Java -jar deployment/jetty-runner-9.4.9.v20180320.jar --port 8081 paste4j.war

Mais à ce stade, ces avertissements commencent à apparaître. Qu'est-ce que je fais mal?

Voici les fichiers que j'ai:

WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://Java.Sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://Java.Sun.com/xml/ns/javaee http://Java.Sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID"
    version="3.1">
    <servlet>
        <servlet-name>rest</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.paste.ws.MyApplication</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>rest</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>

WEB-INF/classes/com/coller/ws/MonApplication.Java

package com.paste.ws;

import org.glassfish.jersey.server.ResourceConfig;

public class MyApplication extends ResourceConfig {
    public MyApplication() {
        packages("com.paste.ws");
    }
}

WEB-INF/classes/com/coller/ws/PasteResource.Java

package com.paste.ws;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/hello")
public class PasteResource {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getMessage() {
        return "Hello there";
    }
}

Et la structure:

 enter image description here

La version Java (Sudo apt install openjdk-8-jdk):

$ Java -version
openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195246.buildd.src)
OpenJDK 64-Bit Server VM (build 9-internal+0-2016-04-14-195246.buildd.src, mixed mode)

L'application fonctionne quand je l'appelle, mais vous ne savez pas si ces avertissements peuvent être ignorés?:

$ curl localhost:8081/rest/hello
Hello there
8
Juha Untinen

Il y a des doublons ici. Jersey est connu pour le reconditionnement des classes dans ses propres fichiers JAR à cause de OSGI. Ce qui est nul si vous n'utilisez pas et ne comprenez pas OSGI comme moi. Je ne les connais pas tous, mais par exemple, javax.inject-1 et javax.inject-2.5.0-b42 sont identiques. La plupart des gens utilisent maven, qui est un meilleur moyen de gérer les dépendances (mais une courbe d’apprentissage abrupte à franchir) et qui exclurait alors celle reconditionnée du maillot comme:

   <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <exclusions>
            <exclusion><!-- Exclude this repackaged javax.inject. -->
                <groupId>org.glassfish.hk2.external</groupId>
                <artifactId>javax.inject</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.inject</groupId>
        <artifactId>jersey-hk2</artifactId>
        <exclusions>
            <exclusion><!-- Exclude this repackaged javax.inject. -->
                <groupId>org.glassfish.hk2.external</groupId>
                <artifactId>javax.inject</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Mais dans votre cas, essayez simplement de supprimer javax.inject-2.5.0-b42 et voyez si vous n'obtenez plus d'avertissement pour ces classes:  enter image description here

Vous devrez aussi trouver les doublons pour les autres avertissements. Pour moi, cela a été un peu plus facile, car j’ai utilisé maven et le graphe de dépendance de netbeans pour trouver les doublons. J'espère que cela n'a pas gâché votre retour à Java. 

1
Leejjon