10

Getting back to Java after some time, and I'm trying to get a simple RESTful API going on with Java 8, Jersey 2.27 and Jetty 9.4.9 using the command line. The app does work, but I keep getting hundreds of warnings like:

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

I have extracted the contents of jaxrs-ri-2.27.zip from https://jersey.github.io/download.html into the project WEB-INF\lib\ directory, so that all JAR files from the ZIP are in the same directory.

Then I compile it with:

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

And finally attempt to run it with:

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

But at that point, those warnings start to appear. What am I doing wrong?

Here's the files I have:

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/paste/ws/MyApplication.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/paste/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";
    }
}

And the structure:

enter image description here

The java version (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)

The app does work when I call it - but not sure if those warnings are safe to ignore?:

$ curl localhost:8081/rest/hello
Hello there
1
  • 4
    Did you ever resolve this issue? Commented Jul 19, 2018 at 20:14

1 Answer 1

3

There are duplicates in there. Jersey is known for repackaging classes in it's own jars because of OSGI. Which sucks if you don't use and understand OSGI like me. I don't know all of them but for example javax.inject-1 and javax.inject-2.5.0-b42 are the same. Most people use maven which is a better way to manage dependencies (but a steep learning curve to get into) and then would exclude the repackaged one from jersey like:

   <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>

But in your case just try to remove javax.inject-2.5.0-b42 and see if you get no more warnings for these classes: enter image description here

You'll have to figure out the duplicates for the other warnings too. For me it was a little easier because I used maven and the dependency graph in netbeans to find duplicates. Hope this didn't ruin your return to Java.

Not the answer you're looking for? Browse other questions tagged or ask your own question.