maven 创建 jersey 项目

如果没找到 jersey archetype, 下载 maven 的 archetype xml, 然后导入 archetypes

运行

右击 main.java -> Run As -> Java Application

如果 pom.xml 报错: Missing artifact com.sun.jersey:jersey-client:jar:${jersey-

version}, 则需要修改 jersey 版本号, 找到 pom.xml 中的

    <properties>
<jersey-version>${jersey-version}</jersey-version>
</properties>

改成

    <properties>
<jersey-version>1.19.1</jersey-version>
</properties>

运行成功,在 Console 栏位下会显示

在浏览器输入 http://localhost:9998/application.wadl, 看到可访问的 api

然后在浏览器输入 http://localhost:9998/myresource

支持返回 json 数据对象

在 pom.xml 添加

		<dependency>
<groupId>com.owlike</groupId>
<artifactId>genson</artifactId>
<version>0.99</version>
</dependency>

在 java 文件中就可直接返回对象

    @GET
@Path("hello")
@Produces(MediaType.APPLICATION_JSON)
public UserInfo hello(){
UserInfo user = new UserInfo();
user._id = "id";
user._name = "haha";
return user;
} public class UserInfo{
String _id;
String _name;
public String getId(){
return this._id;
}
public void setId(String id){
this._id= id;
}
public String getName(){
return this._name;
}
public void setName(String name){
this._name = name;
}
}

eclipse + maven + com.sun.jersey 创建 restful api的更多相关文章

  1. eclipse + maven + org.glassfish.jersey 创建 webapi

    org.glassfish.jersey 和 com.sun.jersey 的区别是,jersy version 2 之前是 com.sun.jersy, 之后改名为 org.glassfish.je ...

  2. 第四篇:用IntelliJ IDEA 搭建基于jersey的RESTful api

    编译器:Intellij IDEA 系统环境: MAC OS 相关技术:Maven.tomcat 7.jdk8 1.创建项目 首先创建一个web Application项目(这里我们打算用maven引 ...

  3. 【从0到1,搭建Spring Boot+RESTful API+Shiro+Mybatis+SQLServer权限系统】03、创建RESTful API,并统一处理返回值

    本节应用Spring对RESTful的支持,使用了如@RestController等注解实现RESTful控制器. 如果对Spring中的RESTful不太明白,请查看相关书籍 1.创建一个数据对象, ...

  4. 使用Django创建RESTful API

    Agenda 1.What is an api Api refers to application programming interface It is a set of subroutine de ...

  5. Eclipse + Jersey 发布RESTful WebService(一)了解Maven和Jersey,创建一个WS项目(成功!)

    一.下文中需要的资源地址汇总 Maven Apache Maven网站 http://maven.apache.org/ Maven下载地址: http://maven.apache.org/down ...

  6. 使用 SpringBoot 构建一个RESTful API

    目录 背景 创建 SpringBoot 项目/模块 SpringBoot pom.xml api pom.xml 创建 RESTful API 应用 @SpringBootApplication @C ...

  7. RESTful API Develop

    yii2 RESTful API Develop   参考文档:http://www.yiiframework.com/doc-2.0/guide-rest.html 以 DB 中的 news 表为例 ...

  8. 如何在SAP C4C里使用ABSL消费第三方Restful API

    首先我们得有一个可以正常工作的Restful API: 然后在Cloud for Customer的Cloud Application Studio里创建Restful API的模型,把第一步可以正常 ...

  9. yii2 RESTful API Develop

    参考文档:http://www.yiiframework.com/doc-2.0/guide-rest.html 以 DB 中的 news 表为例创建该资源的 RESTful API,最终的测试通过工 ...

随机推荐

  1. Sqlserver数据库中,跨权限执行语句

    问题来源:最近有同事需要执行批量删除语句.根据他提供的业务需求,推荐他使用“TRUNCATE TABLE”语句.但使用该语句需要 ALTER权限,这与执行用户的角色不符. 解决办法:使用EXECUTE ...

  2. 【转载】Please configure Android Sdk(android studio)解决办法

    https://blog.csdn.net/u011622280/article/details/79005453 studio就报Please configure Android Sdk,重启and ...

  3. python-ldap修改AD域用户密码(CA+SSL)

    代码连接:https://github.com/raykuan/ldap-notes 使用python的ldap模块连接AD服务器,有两种方式: 非加密:con = ldap.initialize(' ...

  4. Django有关的所有命令

    1. Django的安装 pip install django ==1.11.11 pip install -i yuan django==1.11.11 2. 创建项目 django-admin s ...

  5. 乘风破浪:LeetCode真题_024_Swap Nodes in Pairs

    乘风破浪:LeetCode真题_024_Swap Nodes in Pairs 一.前言 这次还是链表的操作,不过我们需要交换链表奇数和偶数位置上的节点,因此要怎么做呢? 二.Swap Nodes i ...

  6. DevExpress10、RichEditControl

    1.概述 传统.NET界面也有一个RichTextBox控件,一个富文本控件,可存储图片文字,有自己的文件格式RTF. 在DevExpress控件组里面也有一个同等的控件,RichEditContro ...

  7. github团队使用记录

    Last login: Sat Nov 4 09:20:15 on ttys000 bogon:~ neveszhang$ git clone git@github.com:031502243/Cla ...

  8. 2.js深入(以通俗易懂的语言解释JavaScript)

    1.函数返回值: 即函数的执行结果 可以没有return 经验:一个函数应该只返回一种类型的值 2.函数传参 可变参(不定参):arguments ——>(参数的个数可变,参数数组) 例子1:求 ...

  9. postMessage 消息传递

    点击查看demo 前言 web开发了,除了前台与服务器交换数据,还有可能前台页面间需要进行数据传递,比如窗口间,页面和嵌套的iframe间.这些问题之前都有解决办法,但是现在html5引入的messa ...

  10. CF700E:Cool Slogans(SAM,线段树合并)

    Description 给你一个字符串,如果一个串包含两个可有交集的相同子串,那么这个串的价值就是子串的价值+1.问你给定字符串的最大价值子串的价值. Input 第一行读入字符串长度$n$,第二行是 ...