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. windows-oracle 11g dataguard with dgbroker

    一: DG的配置 oracle dg 考验dba综合能力.首先明确3个知识点: SID, SERVICE_NAME,,DB_NAME, DB_UNIQUE_NAME SID: 实例名,用于标识一个数据 ...

  2. python被游标坑了

    为了方便,这次就不单独写脚本了,直接一步一步执行下来就好了先说下游标,就是一个指针,比如我有1234每条占一行,那么初始游标默认是在1的位置,当read(1)后,游标自动向下next,现在指在2的位置 ...

  3. linux通配符含义

    linux通配符含义: .    当前目录**** ..   当前目录的上一级目录**** *    通配符,代表任意0个或多个字符***** ?   通配符,代表重复0个或一个0前面的字符 :    ...

  4. node.js 笔记一

    现在地址:http://nodejs.org/download/ 我的机器是windows的,选择的文件是,是编译后的版本:Windows Installer (.msi)  32-bit examp ...

  5. eclipse能正常启动tomcat,但是网页访问不了

    参考网址https://blog.csdn.net/did_itmyway/article/details/62099930

  6. js面对对象编程(二):属性和闭包

    上篇博客中解说了一些js对象的基本概念和使用方法.这篇博客解说一下js属性方面的:公有属性.私有属性,特权方法. 假设学过java.公有属性.私有属性,特权方法(即能够訪问和设置私有属性的方法)一定非 ...

  7. PHP常用算法和数据结构示例

    <?php header("content-type:text/html;charset=utf-8"); $arr=array(3,5,8,4,9,6,1,7,2); ec ...

  8. CentOS配置Hive

    hive搭建共分为三种模式:1.embedded,2.local,3.remote server 在这里,主要是配置第3种模式:remote server模式,如下图所示: 我的环境共三台虚拟机:Ho ...

  9. (四)Lua脚本语言入门(数组遍历)

    这篇文章就当成铺垫型的文章,写着写着发现有好多想写的,,关于C#与Java,当然作为铺垫肯定与Lua的下部分介绍有关..... 对于"泛型",先看C#中"泛型" ...

  10. 在mvc视图中实现rdlc报表展示

    需求:在view视图页面中嵌入rdlc报表,rdlc的xml为动态传入的xml字符串.本项目是基于abp框架 可能出现问题: 1.rdlc报表是由asp.net的服务器控件ReportViewer来支 ...