gpt4 book ai didi

java - 在简单的 Jersey Web 应用程序中获取大量 "scanned from multiple locations"警告

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:25:24 25 4
gpt4 key购买 nike

一段时间后回到 Java,我正在尝试使用命令行获得一个简单的 RESTful API,用于 Java 8、Jersey 2.27 和 Jetty 9.4.9。该应用程序确实有效,但我不断收到数百条警告,例如:

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

我已经从https://jersey.github.io/download.html 中提取了jaxrs-ri-2.27.zip 的内容。进入项目 WEB-INF\lib\ 目录,以便 ZIP 中的所有 JAR 文件都在同一目录中。

然后我编译它:

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

最后尝试运行它:

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

但就在那时,这些警告开始出现。我做错了什么?

这是我的文件:

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";
}
}

和结构:

enter image description here

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)

当我调用该应用程序时它确实可以运行 - 但不确定这些警告是否可以安全忽略?:

$ curl localhost:8081/rest/hello
Hello there

最佳答案

里面有重复的。由于 OSGI,Jersey 以在它自己的 jar 中重新打包类而闻名。如果您不像我一样使用和理解 OSGI,那就太糟糕了。我不知道所有这些,但例如 javax.inject-1 和 javax.inject-2.5.0-b42 是相同的。大多数人使用 maven,这是一种更好的管理依赖关系的方法(但学习曲线陡峭),然后将重新打包的从 jersey 中排除,例如:

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

但在您的情况下,只需尝试删除 javax.inject-2.5.0-b42 并查看是否不再收到这些类的警告: enter image description here

您还必须找出其他警告的重复项。对我来说,这要容易一些,因为我使用 maven 和 netbeans 中的依赖图来查找重复项。希望这不会破坏您对 Java 的回归。

关于java - 在简单的 Jersey Web 应用程序中获取大量 "scanned from multiple locations"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50052838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com