- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想用 JAX-RS 编写一个 RESTful web 服务,我想在本地主机上发布它,比如 http://localhost:[port]
。我在这个 answer 中阅读了以下内容:
The Java SE 7 (JSR 336) and the Java SE 8 (JSR 337) specifications don't incorporate the JAX-RS component. However, JAX-RS applications can be published in Java SE environments (using
RuntimeDelegate
) and JAX-RS implementations also may support publication via JAX-WS.
提到了 RuntimeDelegate
。我该如何使用它?如果有关于如何完成任务的好例子,请与我分享。
最佳答案
要在 Java SE 环境中部署 JAX-RS 应用程序,您可以使用 RuntimeDelegate
以及您的 JAX-RS 实现支持的 HTTP 服务器。不需要 servlet 容器。
JSR 339陈述如下:
In a Java SE environment a configured instance of an endpoint class can be obtained using the
createEndpoint
method ofRuntimeDelegate
. The application supplies an instance ofApplication
and the type of endpoint required. An implementation MAY support zero or more endpoint types of any desired type.How the resulting endpoint class instance is used to publish the application is outside the scope of this specification.
Jersey,JAX-RS 引用实现,支持 range of HTTP servers您可以使用它在 Java SE 中部署 JAX-RS 应用程序。
例如,Grizzly和 RuntimeDelegate
,你可以有以下内容:
public class Example {
public static void main(String[] args) {
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(GreetingsResource.class);
HttpHandler handler = RuntimeDelegate.getInstance()
.createEndpoint(resourceConfig, HttpHandler.class);
HttpServer server = HttpServer.createSimpleServer(null, 8080);
server.getServerConfiguration().addHttpHandler(handler);
try {
server.start();
System.out.println("Press any key to stop the server...");
System.in.read();
} catch (Exception e) {
System.err.println(e);
}
}
@Path("/greetings")
public static class GreetingsResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getGreeting(){
return "Hello from the other side.";
}
}
}
该应用程序将在 http://localhost:8080/greetings
上可用。
上面显示的示例需要以下依赖项:
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-server</artifactId>
<version>2.3.30</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>2.25.1</version>
</dependency>
其他支持的实现包括:
Jersey documentation还描述了没有 RuntimeDelegate
的 Java SE 环境的其他部署方案。 .
关于java - 如何在 Java SE 环境中部署 JAX-RS 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43278950/
我无法从远程 Ubuntu 服务器打开在本地 macOS 机器上运行的 Stata 的 GUI。 我已经安装了stata-se在我的本地机器上,我可以打开 X11 应用程序,如 xclock和 xey
我正在尝试将 tobit 模型从 Stata 迁移到 R。 稳健的 Stata 命令只需将 ,vce(robust) 添加到模型中。对于集群,它将是 ,vce(cluster idvar)。 可重现的
以下代码在 JavaSE 6 中工作正常,但在 JavaSE 7 中执行时抛出 ConnectException(超时)。这是 JDK7 错误还是错误代码?实在是看不懂…… public sta
在 SE 6 或 SE 7 的任何类中是否有任何地方不是最终的,即可以直接设置的字段? 我正在研究从另一种语言 (Haskell) 到 Java 的绑定(bind),我正在寻找那个特定的案例来检查我的
我想学习 Java,特别是 Android 开发,因为我要买一台新的平板电脑,但也想学习 Java 可以做的许多其他事情(Struts、网络开发、JWebSockets 等)。我是一位在 PHP、Ja
我正在尝试使用 websockets 编写一些东西,但遇到了无法解析的导入问题。 经过几次尝试,我创建了两个相同的项目。一份使用 Java SE9,一份使用 JAVA SE-1.8。 导入适用于 1.
我使用 Weld SE 创建了一个简单的 JavaSE 应用程序。我正在尝试使用 gradle run 运行它会抛出异常: :compileJava UP-TO-DATE :processResour
我正在尝试将现有应用程序的 Java JDK 版本从 Java 5 更改为 Java 6(更新 38)。该应用程序使用一些 JAXB 生成的类来编码/解码我们从远程服务器发送/接收的 XML。 XML
我有一个命令行 Java 应用程序,它在 Windows 7 x64 平台上读写文件。当前应用程序使用随附的 IBM Java SE 6 运行。结构如下: APP_ROOT some_fold
在主题中,我有一个使用 Java 1.6 编译的 Java SE 应用程序部署在 Java 1.7 运行时环境中。由于 Java 是高度向后兼容的,我假设一切都会很好 - 但自从它部署在 1.7 环境
我正在开发一个 JavaFX 2 项目,并且该应用程序必须使用另一个 main 方法(根据生成的 JAR list 为 com.javafx.main.Main)启动。据官方焊缝reference引导
内部类 1. 内部类的概述 内部类指的是****把类定义在另一个类的内部,该类就被称为内部类。类名不需要和源文件名相同。 内部类的种类: 在Java中,内部类的使用共有两种情况: (1). 在类中定义
我正在开发一个 Java 应用程序,用于在 yfrog.com 上上传图像。 我可以在API页面成功发帖但没有二进制文件,只有一个字符串参数 . 另外我使用的方法只接受“字符串”。 URLConnec
我在我的应用程序中创建了一个与端口绑定(bind)的 ServerSocket。我将此应用程序分发到同一网络上连接的 PC。我可以使用此端口向安装了该应用程序的任何 PC 发送请求。现在接收者可以接收
我已经解决了Java SE Security特点。 据我了解,此标准功能的整体理念是保护用户免受恶意软件的侵害。 对于 Web 上的两个 Java 应用程序,默认情况下启用 SecurityManag
当我编译代码时,我的 java 应用程序出现问题,它说找不到符号 roomLength。应用程序应该做的是提示用户输入房间名称,然后如果它是“退出”,那么它必须关闭程序。否则会提示房间的长、宽、高。如
我不明白为什么下面的代码返回“false” String x="Hello World"; String z=" Hello World".trim(); System.out.println(x==
首先,我要说的是我在观看此视频时完成了所有这些操作:https://www.youtube.com/watch?v=Hl-zzrqQoSE 所以,我尝试下载适用于 Windows 64 位的 jdk-
我正在尝试创建一个具有用户友好界面的网络Java SE应用程序,我对GUI库(Swing、SWT、JavaFX)感到很困惑 以及关于应用程序 (MVC、PureMVC) 的架构 任何有经验的人都可以给
拜托,我有一个 java 桌面应用程序,我想要一种将我的桌面应用程序连接到在线数据库的方法。我想知道可用于执行此操作的技术。 最佳答案 您可以只使用 JDBC。 您必须创建与数据库属性的连接,例如:
我是一名优秀的程序员,十分优秀!