我坚持使用jersey库为RESTful Web服务创建gradle项目。项目配置应该能够在jetty应用程序服务器中启动服务。我已经找到了一个资源:https://github.com/ziroby/jetty-gradle-hello-world
我对这种解决方案的问题是,它使用的是一种过时的球衣版本。我需要至少版本2(首选最新版本2.14)。我试图在maven central上搜索新版本,但在版本2中,许多工件名称发生了更改,我无法正确配置它。
编辑:我的项目中并不特别需要jetty服务器。它可以是任何适用于测试和调试我的应用程序的应用程序服务器。我也在生产中使用jetty,所以使用jetty会很好。
编辑:(通过peeskillet)-链接中的代码
构建
apply plugin: 'java'
apply plugin: 'jetty'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.11'
testCompile 'org.hamcrest:hamcrest-all:1.3'
testCompile 'com.sun.jersey:jersey-client:1.17.1'
testCompile 'com.sun.jersey:jersey-core:1.17.1'
compile 'com.sun.jersey:jersey-core:1.17.1'
compile 'com.sun.jersey:jersey-server:1.17.1'
compile 'com.sun.jersey:jersey-servlet:1.17.1'
}
test {
exclude '**/*IntegrationTest*'
}
task integrationTest(type: Test) {
include '**/*IntegrationTest*'
doFirst {
jettyRun.httpPort = 8080 // Port for test
jettyRun.daemon = true
jettyRun.execute()
}
doLast {
jettyStop.stopPort = 8091 // Port for stop signal
jettyStop.stopKey = 'stopKey'
jettyStop.execute()
}
}
测试
public class HelloIntegrationTest {
private static String HELLO_URL = "http://localhost:8080/hello";
@Test
public void testHello() throws Exception {
Client client = Client.create();
WebResource webResource = client.resource(HELLO_URL);
String response = webResource.get(String.class);
assertThat(response, is("Hello, World!"));
}
}
资源
@Path("/hello")
public class HelloWebapp {
private static HelloWorldService helloWorldService = new HelloWorldService();
@GET()
public String hello() {
return helloWorldService.sayHello();
}
}
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Jetty Gradle Hello World</display-name>
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.ziroby.hello.webapp</param-value>
</init-param>
<!-- <init-param> -->
<!-- <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name> -->
<!-- <param-value>true</param-value> -->
<!-- </init-param> -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
摆脱你目前拥有的所有泽西依赖
dependencies {
testCompile 'junit:junit:4.11'
testCompile 'org.hamcrest:hamcrest-all:1.3'
+------------- ======= JUNK ======= ----------------+
| testCompile 'com.sun.jersey:jersey-client:1.17.1' |
| compile 'com.sun.jersey:jersey-core:1.17.1' |
| compile 'com.sun.jersey:jersey-server:1.17.1' |
| compile 'com.sun.jersey:jersey-servlet:1.17.1' |
+---------------------------------------------------+
}
下面是您唯一需要获得基本功能的
dependencies {
testCompile 'junit:junit:4.11'
testCompile 'org.hamcrest:hamcrest-all:1.3'
+-------------------- ========= GOLDEN ======== -------------------------+
| compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.14'|
+------------------------------------------------------------------------+
/* UPDATE */
/* Starting Jersey version 2.26, you will also need the following */
/* compile 'org.glassfish.jersey.inject:jersey-hk2:2.26' */
}
web.xml
<web-app>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>
org.glassfish.jersey.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.ziroby.hello.webapp</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
public class HelloIntegrationTest {
private static String HELLO_URL = "http://localhost:8080/hello";
@Test
public void testHello() throws Exception {
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(HELLO_URL);
String response = webTarget.request().get(String.class);
System.out.println(response);
assertThat(response, is("Hello, World!"));
}
}
这已经通过链接项目的克隆进行了测试。上面只显示了更改。
其他资源:
用于JSON支持
org.glassfish.jersey.media:jersey-media-json-jackson:2.14
它不需要额外的配置即可工作。
含安装程序的源码但不包含lerx v2的源码。 安装说明: 1.本安装程序是用Java自行开发的,已自带java环境。自动侦测msvcr71.dll。 2.测试环境:全新安装的Windows 2003 Server、XP、Windows 7(未安装任何软件)。 3.安装程序将安装及自动配置 Java环境、MySQL Server 5.0、Tomcat及Lerx V2。
一、安装 请按照您的操作系统的步骤进行操作。 1、苹果系统 在macOS上安装mitmproxy的推荐方法是使用Homebrew: brew install mitmproxy 或者,您可以在mitmproxy.org上下载独立的二进制文件。 2、Linux 在Linux上安装mitmproxy推荐的方法是下载的独立二进制代码mitmproxy.org。 一些Linux发行版通过其本机软件包存储库
本文向大家介绍Python安装图文教程 Pycharm安装教程,包括了Python安装图文教程 Pycharm安装教程的使用技巧和注意事项,需要的朋友参考一下 本教程为大家分享了Pycharm及Python安装的详细步骤,供大家参考,具体内容如下 第一步:安装python 1 首先进入网站下载:点击打开链接,进入之后如下图,选择图中红色圈中区域进行下载 2 双击exe文件进行安装,如下图,并按照圈
我下载了Visual Studio Ultimate CTP 6的完整ISO。安装程序达到了90%左右,通过进度条进行测量,然后就卡在那里了。Superfetch、反恶意软件保护和其他后台进程的活动频繁,但进度条仍然死气沉沉。最终,后台任务活动在20分钟后消退,但进度条仍不动。 便宜的技巧:打开一个记事本窗口,并将其左边缘定位,使其完美地标记进度条的当前位置。如果进度条在大约一个小时内没有移动过记
问题内容: 我正在尝试在Ubuntu PC上使用composer安装laravel安装程序,但是在安装过程中出现此错误。您的要求无法解决为一组可安装的软件包。 出现错误,然后我使用此注释: 问题答案: 它说它需要 zip扩展名 laravel / installer v1.4.0需要ext-zip ........ 安装与已安装的php版本相对应的版本:
我有Inno安装程序(在我之前写的),它提取了一组VSTO文件并开始安装VSTO MS Office插件。它有一个问题,当将VSTO文件提取到临时文件夹并启动时,它会立即显示完成按钮。如果用户单击它,临时文件将被删除,并在中开始实际安装VSTO插件,然后导致“文件未找到”错误。我应该解决这个问题(理想情况下,只有当它生成的完成执行时,Inno安装程序中的完成按钮才会出现)。 VSTO包本身(“应用
现在如果我用这个命令 它将创建一个具有最新版本(如5.2)的laravel项目,但是如果我想安装一个特定的版本(如5.1版),该怎么办? 更新::我正在寻找laravel安装程序命令,是否有任何选项/参数用于特定版本的安装?
在命令提示符下通过pip installer for Python3.7安装pandas时,我反复遇到以下错误 我已经通过管理员运行了该命令,但它没有运行。