- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
一段时间后回到 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";
}
}
和结构:
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 并查看是否不再收到这些类的警告:
您还必须找出其他警告的重复项。对我来说,这要容易一些,因为我使用 maven 和 netbeans 中的依赖图来查找重复项。希望这不会破坏您对 Java 的回归。
关于java - 在简单的 Jersey Web 应用程序中获取大量 "scanned from multiple locations"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50052838/
我已阅读 Jersey documentation ,并表示 Jersey 在读取实体后自动关闭连接(例如 response.readEntity(SomeObject.class)) 但是当抛出异常
Jersey vs Jersey (Standalone) vs Jersey with Grizzly vs Jersey with Tomcat - for REST services 有什么区别
如何通过 guice 使用非 Jersey 资源和 Jersey 资源? 我希望“/”由普通 servlet 处理。但我希望 Jersey 处理“/users”。 假设我有一个带@Path("/use
我正在尝试使用 Maven、Apache Tomcat 7.0、Eclipse IDE 创建一个基本的 RESTful 应用程序。我在 google 提供的一些示例代码中遇到了 jersey-serv
我已经从 Jersey 1.7 升级到 2.16,但 Jersey 似乎无法找到我的资源(请参阅下面的堆栈)。任何想法发生了什么?我尝试在扩展 ResourceConfig 的自定义应用程序类中初始化
我正在使用 com.yammer.dropwizard.config.Environment addProvider 方法在 Jersey 中注册提供程序。我也有一个自定义提供程序,它执行类似于 Dr
在 Jersey 1.x 中,您可以使用 ContainerRequest.getFormParameters()对表单数据进行请求过滤,但我在 Jersey 2.x 中看不到明显的等价物。我已经实现
我正在使用Jersey的集成Jackson处理将传入的JSON转换为POJO,例如: @POST @Consumes(MediaType.APPLICATION_JSON) public Respon
我正在尝试以编程方式创建 Jersey 资源(没有注释)。我有一个将 Name 和 id 作为输入参数的方法 raiseAlarm。我想从 JSON 输入中获取名称,并且我希望 id 来自路径参数。代
Dropwizard official documentation Jersey 客户端不可测试,有人有 dropwizard Jersey 客户端样本吗? 最佳答案 我发现在 Dropwizard
我一直在寻找解决这个问题的方法,但没有成功。我发现的最新帖子可以追溯到 2010 年。我正在使用带有嵌入式 grizzly 2.2.1 的 Jersey 1.12。 如果我理解正确,除非我将 Jers
我想开发一个 Web API,它将生成和使用 JSON 和 XML 数据。 我已经使用JAXB来支持XML,并且工作正常。现在我想添加 JSON 类型。我研究了不同的教程,所有教程都使用不同的依赖项,
如此处所述:http://wikis.sun.com/display/Jersey/WADL 我在 Tomcat 6 中使用 Jersey 1.4。 我已经尝试了所有可能的带有“/applicatio
我是jax-rs的新手,并且已经用jersey和glassfish构建了Web服务。 我需要的是一种方法,服务启动后即被称为。在这种方法中,我想加载自定义配置文件,设置一些属性,编写日志等等。 我尝试
当客户端请求 Not Acceptable MIME 类型时,如何防止 Jersey 在客户端发送 HTML 页面?我想使用 ExceptionMapper,但我不确定要捕获什么异常,或者这是否是处理
我试图在它的 JSON 被解码后拦截一个资源调用。通过阅读一些论坛和帖子,我发现我可以通过实现 来做到这一点。 org.glassfish.jersey.server.spi.internal.Res
我的 webapp 包含一个库,其中包含一个用 @javax.ws.rs.ext.Provider 注释的类。 .如果存在此类,我的 web 应用程序(在 EAR 中部署为 WAR)将无法启动并显示以
我想自定义404响应,即服务器(不是我)在找不到请求的资源时抛出(或自己抛出一个自定义的WebApplicationException,如果可以测试一个应用程序中是否存在请求的资源)?资源列表存储在某
我有一个受 Shibboleth(SSO 实现)保护的 Jersey API。 Shibboleth 将登录用户的 ID 放入请求属性中。在后端,我使用 Shiro 进行授权。 Shiro 希望了解登
我目前正在使用 Jersey 返回 JSON。我该如何返回 JSONP?例如我当前的RESTful方法是: @GET @Produces(MediaType.APPLICATION_JSON) pub
我是一名优秀的程序员,十分优秀!