eclipse + maven + org.glassfish.jersey 创建 webapi
org.glassfish.jersey 和 com.sun.jersey 的区别是,jersy version 2 之前是 com.sun.jersy, 之后改名为 org.glassfish.jersey, 所以想用 jersey 新版本就用 org.glassfish.jersey;
创建

支持返回 json 对象
pom
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.25.1</version>
</dependency>
@GET
@Produces(MediaType.APPLICATION_JSON)
public UserInfo getIt() {
UserInfo user = new UserInfo();
user.setId("1");
user.setName("grissom");
return user;
}
错误: Exception in thread "main" java.lang.NoSuchMethodError: org.glassfish.jersey.CommonProperties.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object; ,修改jersey 版本号,和 json 一致
<properties>
<jersey.version>2.25.1</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
错误: org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
去掉或注释下面这段
<!-- uncomment this to get JSON support:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>-->
错误 Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.ClientConfig ,添加
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25.1</version>
<scope>provided</scope>
</dependency>
错误 Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor ,添加
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
我的 demo pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.easymerylife.member</groupId>
<artifactId>member</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>member</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.easymerylife.member.member.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jersey.version>2.25.1</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
eclipse + maven + org.glassfish.jersey 创建 webapi的更多相关文章
- eclipse + maven + com.sun.jersey 创建 restful api
maven 创建 jersey 项目 如果没找到 jersey archetype, 下载 maven 的 archetype xml, 然后导入 archetypes 运行 右击 main.java ...
- Eclipse+Maven创建webapp项目<一>(转)
还在为jar下载而烦恼吗?还在为jar依赖关系而烦恼吗?还在为jar冲突而烦恼吗?强大的maven项目管理工具来拯救你们呢?自动下载jar,自动下载jar依赖包.你什么都不用做,只需要在中央仓库中co ...
- Eclipse+maven创建webapp项目<二>(转)
原文地址:http://www.cnblogs.com/candle806/p/3439469.html 1.开启eclipse,右键new-->other,如下图找到maven project ...
- Eclipse+Maven创建webapp项目
Eclipse+Maven创建webapp项目<一> 1.开启eclipse,右键new-->other,如下图找到maven project 2.选择maven project,显 ...
- Eclipse+Maven创建webapp项目<一>
Eclipse+Maven创建webapp项目<一> 1.开启eclipse,右键new——>other,如下图找到maven project 2.选择maven project,显 ...
- Eclipse+Maven创建webapp项目<一><二><三>
转-http://www.cnblogs.com/candle806/p/3439469.html Eclipse+Maven创建webapp项目<一> 1.开启eclipse,右键new ...
- Eclipse+Maven创建webapp项目<二> (转)
Eclipse+Maven创建webapp项目<二> 1.开启eclipse,右键new——>other,如下图找到maven project 2.选择maven project,显 ...
- Eclipse+Maven创建webapp项目<一> (转)
Eclipse+Maven创建webapp项目<一> 1.开启eclipse,右键new——>other,如下图找到maven project 2.选择maven project,显 ...
- JavaEE开发基于Eclipse的环境搭建以及Maven Web App的创建
本篇博客就完整的来聊一下如何在Eclipse中创建的Maven Project.本篇博客是JavaEE开发的开篇,也是基础.本篇博客的内容干货还是比较多的,而且比较实用,并且都是采用目前最新版本的工具 ...
随机推荐
- SQL Server中事务transaction如果没写在try catch中,就算中间语句报错还是会提交
假如我们数据库中有两张表Person和Book Person表: CREATE TABLE [dbo].[Person]( ,) NOT NULL, ) NULL, ) NULL, [CreateTi ...
- Node.js环境搭建和学习(windwos环境)
Node.js环境搭建和学习 一.环境搭建 1.下载安装文件 下载地址http://nodejs-org.qiniudn.com/下载Node.js环境安装包,根据操作系统下载对应的安装包 下载地址 ...
- Centos7(Firewall)防火墙开启常见端口命令
Centos7默认安装了firewalld,如果没有安装的话,则需要YUM命令安装:firewalld真的用不习惯,与之前的iptable防火墙区别太大,但毕竟是未来主流讲究慢慢磨合它的设置规则: 安 ...
- 匿名访问windows server 2008 R2 文件服务器的共享
匿名访问windows server 2008 R2 文件服务器的共享 匿名访问windows 2008 R2 文件服务器的共享,七步:第一步 取消简单文件共享:第二步 设置需要共享的文件夹every ...
- Resharper安装使用手册
今天在博客园上看到一位大牛写了一遍关于.NET代码优化的文章,其中提到了Resharper这个工具,以前没使用过这个工具,突然想用这个工具来检查一下自己之前代码的规范程度,也是为了写出更规范的代码. ...
- October 30th, 2017 Week 44th Monday
When you're eighteen your emotions are violent, but they're not durable. 年轻的时候我们总是激情有余但耐心不足. I reall ...
- SDN期末验收
队名:取个队名真难 一.网络拓扑 二.负载均衡程序 1.建立拓扑的代码 拓扑 2.下发组表流表的代码 下发流表 三.演示视频 1.目的 服务器h2,h3,h4上各自有不同的服务,h1是客户端.实现一个 ...
- uwsgi+django 配置
uwsgi+django 创建新的虚拟环境,且解决crm的环境依赖 在虚拟环境下安装uwsgi pip3 install uwsgi 学习uwsgi命令,如何启动python应用 启动python w ...
- 主机ping不通virtualbox虚拟机的解决办法
虚拟机与主机之间相互ping通有一个问题,就是虚拟机能够ping通主机 本地主机ping不通虚拟机: 解决办法: 1)如果虚拟机有两个网卡: 将虚拟机网卡2的连接方式改成桥接即可: ⚠️要将虚拟机重启 ...
- shiro实战系列(十三)之单元测试
由于我们已经涉及到了 Subject reference,我们知道 Subject 是“当前执行”用户的特定安全视图,且该 Subject 实 例绑定到一个线程来确保我们知道在线程执行期间的任何时间是 ...