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. MySQL数据行溢出的深入理解

    一.从常见的报错说起 故事的开头我们先来看一个常见的sql报错信息: 相信对于这类报错大家一定遇到过很多次了,特别对于OMG这种已内容生产为主要工作核心的BG,在内容线的存储中,数据大一定是个绕不开的 ...

  2. 【转】Zookeeper学习---zookeeper 选举机制介绍

    [原文]https://www.toutiao.com/i6593162565872779784/ zookeeper集群 配置多个实例共同构成一个集群对外提供服务以达到水平扩展的目的,每个服务器上的 ...

  3. 【转】Mysql学习---SQL的优化

    [原文]https://www.toutiao.com/i6594314336913588743/ mysql如何处理亿级数据,第一个阶段--优化SQL语句 1.应尽量避免在 where 子句中使用! ...

  4. Windows7 添加快速启动栏

    解决方案: 1.右击任务栏空白处,选择“工具栏”,单击“新建工具栏”: 2.输入“%userprofile%\AppData\Roaming\Microsoft\Internet Explorer\Q ...

  5. 嵌入式开发板LInux更新系统、安装软件、下载资源碰到的问题

    CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none 先同步系统时间 shell 输入命令 date 如果显示的时间跟你本地时间不一样,先设 ...

  6. 1)HDFS分布式文件系统 2)HDFS核心设计 3 )HDFS体系结构

    一.HDFS简介 1.HDFS:Hadoop distributed file system 一个分布式文件系统 基于流数据模式访问和处理超大文件的需要而开发 适合应用在大规模数据集上 2. 优点 处 ...

  7. 快速数论变换(NTT)

    刚学完FFT,干脆把NTT也学了算了 (一)预备知识 关于原根,这里说得蛮详细的百度百科 为什么使用原根呢?为什么原根可以替代\(\omega_{n}\)呢?想知道为什么就看here NTT用到的各种 ...

  8. 运行metamascara时出现的一些错误

    The difference between mascara and the extension Mascara Is in alpha and some of it's behaviors are ...

  9. java代码,在linux上删除文件

    1.其实在linux上和window是一样的 2.path 传入的路径(直接从根目录到你的文件的位置) public static boolean delFile(String path) { log ...

  10. MP实战系列(十三)之批量修改操作(前后台异步交互)

    MyBatis的批量操作其实同MyBatis基本是一样的.并无多大区别,要说区别,除了封装的方法之外,主要就是注解方面的区别,比如@TableId.@TableField.@TableName等等区别 ...